有没有办法将root用户放到AWS CodeBuild上?我们正在构建一个Yocto项目,如果我们是root用户,它就会在CodeBuild上失败()。
我们孤注一掷的方法也行不通:
...
build:
commands:
- chmod -R 777 $(pwd)/ && chown -R builder $(pwd)/ && su -c "$(pwd)/make.sh" -s /bin/bash builder
...在以下方面失败:
bash: /codebuild/output/src624711770/src/.../make.sh: Permission denied知道我们怎么能用非根的方式运行这个系统吗?
发布于 2018-07-19 11:50:09
我们最后所做的是:
创建一个Dockerfile,其中包含构建Yocto / Bitbake项目的所有内容,在该项目中,我们将创建所需的资源,并创建用于构建项目的用户builder。
FROM ubuntu:16.04
RUN apt-get update && apt-get -y upgrade
# Required Packages for the Host Development System
RUN apt-get install -y gawk wget git-core diffstat unzip texinfo gcc-multilib \
build-essential chrpath socat cpio python python3 python3-pip python3-pexpect \
xz-utils debianutils iputils-ping vim
# Additional host packages required by poky/scripts/wic
RUN apt-get install -y curl dosfstools mtools parted syslinux tree
# Create a non-root user that will perform the actual build
RUN id builder 2>/dev/null || useradd --uid 30000 --create-home builder
RUN apt-get install -y sudo
RUN echo "builder ALL=(ALL) NOPASSWD: ALL" | tee -a /etc/sudoers
# Fix error "Please use a locale setting which supports utf-8."
# See https://wiki.yoctoproject.org/wiki/TipsAndTricks/ResolvingLocaleIssues
RUN apt-get install -y locales
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
echo 'LANG="en_US.UTF-8"'>/etc/default/locale && \
dpkg-reconfigure --frontend=noninteractive locales && \
update-locale LANG=en_US.UTF-8
ENV LC_ALL en_US.UTF-8
ENV LANG US.UTF-8
ENV LANGUAGE en_US.UTF-8
WORKDIR /home/builder/
ADD ./ ./
USER builder
ENTRYPOINT ["/bin/bash", "-c", "./make.sh"]我们在Codebuild pre_build步骤中构建这个停靠程序,并在运行映像时在ENTRYPOINT中运行实际构建(在make.sh中)。在容器兴奋之后,我们将artifacts复制到Codebuild主机,并将它们放在S3上:
version: 0.2
phases:
pre_build:
commands:
- mkdir ./images
- docker build -t bob .
build:
commands:
- docker run bob:latest
post_build:
commands:
# copy the last excited container's images into host as build artifact
- docker cp $(docker container ls -a | head -2 | tail -1 | awk '{ print $1 }'):/home/builder/yocto-env/build/tmp/deploy/images ./images
- tar -cvzf artifacts.tar.gz ./images/*
artifacts:
files:
- artifacts.tar.gz这种方法的唯一缺点是,我们不能(很容易)使用Codebuild的缓存功能。但是构建对我们来说是足够快的,因为我们白天做本地构建,并且基本上在晚上从头开始重建,这需要大约90分钟(在最强大的Codebuild实例上)。
发布于 2020-06-17 13:47:58
我在AWS CodeBuild中成功地使用了非根用户.
想出一个实用的解决方案,不仅仅是知道一些CodeBuild选项。
每个人都应该注意到run-as选项很容易。
下一个问题是“哪个用户?”;您不能只将任何单词作为用户名。
为了找出哪些用户可用,下一个线索是在CodeBuild提供的码头图像部分。在那里,您将找到一个指向每个图像定义的链接。对我来说,这个链接将我引向GitHub上的这一页
在检查了Dockerfile的源代码之后,我们将知道有一个名为codebuild-user的用户可用。我们可以将这个codebuild-user用于构建规范中的run-as。
然后,我们将面临许多其他问题,因为标准映像只为root安装每种语言的运行时。这是泛泛的解释所能做到的。
对我来说,我想使用Ruby运行时,所以我唯一关心的是Ruby运行时。如果您将CodeBuild用于其他方面,那么您现在就只能靠自己了。
为了利用runtime作为codebuild-user,我们必须从根用户中公开它们。为此,我使用以下命令更改CodeBuild映像所使用的所需权限和CodeBuild所有者。
chmod +x ~
chown -R codebuild-user:codebuild-user ~/.rbenvbundler ()仍然希望访问主目录,这是不可写的。我们必须设置一个环境变量,使其使用其他可写位置作为主目录。环境变量是BUNDLE_USER_HOME。
把所有东西组合在一起;我的构建规范看起来是:
version: 0.2
env:
variables:
RAILS_ENV: test
BUNDLE_USER_HOME: /tmp/bundle-user
BUNDLE_SILENCE_ROOT_WARNING: true
run-as: codebuild-user
phases:
install:
runtime-versions:
ruby: 2.x
run-as: root
commands:
- chmod +x ~
- chown -R codebuild-user:codebuild-user ~/.rbenv
- bundle config set path 'vendor/bundle'
- bundle install
build:
commands:
- bundle exec rails spec
cache:
paths:
- vendor/bundle/**/*我的观点是:
发布于 2018-07-17 16:24:30
谢谢您的这一功能要求。目前您无法在CodeBuild中以非根用户的身份运行,我已将其传递给团队以供进一步审查。您的反馈非常感谢。
https://stackoverflow.com/questions/51365622
复制相似问题