前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Gitlab--CI执行用户问题

Gitlab--CI执行用户问题

作者头像
奋飛
发布2020-05-28 17:06:21
2.2K0
发布2020-05-28 17:06:21
举报
文章被收录于专栏:Super 前端Super 前端

19年团队使用了 Gitlab-CI,做一些自动构建流程。最近团队小伙伴自己尝试搭建流程,参照了我之前发的文章 – Gitlab–CI。但过程中,遇到了用户执行权限的问题。于是有了下面的内容…

问题描述

按照文章(https://cloud.tencent.com/developer/article/1487180)中说明,操作完成发现了权限问题。

问题复盘

首先要明确,CI 默认执行用户为 gitlab-runner

代码语言:javascript
复制
$ ps aux | grep gitlab

/usr/bin/gitlab-ci-multi-runner run --working-directory /home/gitlab-runner --config /etc/gitlab-runner/config.toml --service gitlab-runner --syslog --user gitlab-runner

文章中包括 gitlab-runner 服务启动在内的,所有操作都是使用 sudo。这也是为什么,文章中,将 gitlab-runner 免密使用sudo命令,并在脚本的命令前加上 sudo 的要求。

代码语言:javascript
复制
# 切换到root账号下
$ su
# 添加sudo文件的写权限
$ chmod u+w /etc/sudoers
# 编辑sudoers文件
$ vi /etc/sudoers
# 添加如下内容 允许用户gitlab-runner执行sudo命令,并且在执行的时候不输入密码
gitlab-runner ALL=(ALL) NOPASSWD: ALL
# 撤销sudo文件写权限
$ chmod u-w /etc/sudoers

官方关于权限的说明,可参照:Super-user permission

上述内容,是团队小伙伴所忽略的。当然,小伙伴提出了另外一种方式,使用 root 执行。

  1. 修改 /etc/systemd/system/gitlab-runner.service Service ExecStart=/usr/bin/gitlab-ci-multi-runner "run" "--working-directory" "/工作目录" "--config" "/etc/gitlab-runner/config.toml" "--service" "gitlab-runner" "--syslog" "--user" "root" arameter Default Description –service gitlab-runner Specify service name to use –config See the configuration file Specify a custom configuration file to use –syslog true Specify if the service should integrate with system logging service –working-directory the current directory Specify the root directory where all data will be stored when builds will be run with the shell executor –user root Specify the user which will be used to execute builds –password none Specify the password for the user that will be used to execute the builds
  2. 重新加载配置文件,并启动 systemctl daemon-reload systemctl restart gitlab-runner

综上,欢迎大家积极讨论~~~

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2020-04-04 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 问题描述
  • 问题复盘
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档