Skip to content

Commit f53186e

Browse files
committed
ci: run-as unprivileged user
Problem: Running as root causes lots of warnings, latest (fatal) example (#3550): [10429:0609/133041.674749:ERROR:network_service_instance_impl.cc(521)] Network service crashed, restarting service. 19 | [0609/133041.694037:FATAL:electron_main_delegate.cc(304)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180. Solution: - Use "run-as" directive and "export $HOME". - docker is already running, don't need "nohup /usr/local/bin/dockerd". Instead just give the user permissions to the socket: "chmod 666 /var/run/docker.sock" - remove useless things: pylint - TODO: "goenv", "go" are broken...
1 parent fab07b3 commit f53186e

File tree

1 file changed

+46
-17
lines changed

1 file changed

+46
-17
lines changed

buildspec/linuxIntegrationTests.yml

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ phases:
1919
java: latest
2020

2121
commands:
22-
- bash buildspec/setup-github-token.sh
2322
- '>/dev/null add-apt-repository universe'
2423
- '>/dev/null apt-get -qq install -y apt-transport-https'
2524
- '>/dev/null apt-get -qq update'
@@ -33,22 +32,38 @@ phases:
3332
- 'python3.8 --version'
3433
# Dependencies for running vscode.
3534
- '>/dev/null apt-get -yqq install libatk1.0-0 libgtk-3-dev libxss1 xvfb libasound2 libasound2-plugins'
36-
- '>/dev/null pip3 install --upgrade aws-sam-cli'
37-
# Print info about sam (version, location, …).
38-
- 'pip3 show aws-sam-cli'
39-
- '>/dev/null pip3 install --upgrade awscli'
40-
- '>/dev/null pip3 install pylint'
41-
# Install latest version of Go (known to 'goenv')
42-
- '>/dev/null VERSION=$(goenv install --list | tail -n 1) && 2>/dev/null goenv install $VERSION'
43-
- '>/dev/null goenv global $VERSION && go env -w GOPROXY=direct'
44-
- go version
4535
# login to DockerHub so we don't get throttled
46-
- docker login --username $(echo $DOCKER_HUB_TOKEN | jq -r '.username') --password $(echo $DOCKER_HUB_TOKEN | jq -r '.password') || true
36+
# - docker login --username $(echo $DOCKER_HUB_TOKEN | jq -r '.username') --password $(echo $DOCKER_HUB_TOKEN | jq -r '.password') || true
4737
# increase file watcher count so CodeLens tests do not fail unexpectedly (ENOSPC error)
4838
- sysctl fs.inotify.max_user_watches=524288
39+
# start Docker
40+
# - nohup /usr/local/bin/dockerd --host=unix:///var/run/docker.sock --host=tcp://127.0.0.1:2375 --storage-driver=overlay&
41+
- timeout 15 sh -c "until docker info; do echo .; sleep 1; done"
42+
#
43+
# Prepare env for unprivileged user.
44+
#
45+
- |
46+
# - adduser --gecos GECOS --disabled-password codebuild-user
47+
mkdir ~codebuild-user || true
48+
chown -R codebuild-user:codebuild-user ~codebuild-user
49+
chown -R codebuild-user:codebuild-user .
50+
chmod +x ~codebuild-user
51+
ls -ld ~codebuild-user
52+
# Add user to "docker" group.
53+
# - usermod -aG docker codebuild-user
54+
# Ensure that "docker" group has permissions to the socket.
55+
# - chown codebuild-user /var/run/docker.sock
56+
- chmod 666 /var/run/docker.sock
4957

5058
pre_build:
59+
run-as: codebuild-user
60+
env:
61+
variables:
62+
HOME: /home/codebuild-user
5163
commands:
64+
# codebuild ignores the env.variables.HOME declaration above...?
65+
- export HOME=/home/codebuild-user
66+
- bash buildspec/setup-github-token.sh
5267
# If present, log into CodeArtifact. Provides a nice safety net in case NPM is down.
5368
# Should only affect tests run through IDEs team-hosted CodeBuild.
5469
- |
@@ -59,15 +74,29 @@ phases:
5974
echo "CodeArtifact connection failed. Falling back to npm"
6075
fi
6176
fi
62-
# make sure that SAM is in the path, is not automatically done on CodeBuild
63-
- USER_BASE_PATH=$(python -m site --user-base) && export PATH=$PATH:$USER_BASE_PATH/bin
64-
# start Docker
65-
- nohup /usr/local/bin/dockerd --host=unix:///var/run/docker.sock --host=tcp://127.0.0.1:2375 --storage-driver=overlay&
66-
- timeout 15 sh -c "until docker info; do echo .; sleep 1; done"
77+
# Where non-root "pip3 install" puts things:
78+
- 'export PATH="$HOME/.local/bin:$PATH"'
79+
- '>/dev/null pip3 install --upgrade aws-sam-cli'
80+
- '>/dev/null pip3 install --upgrade awscli'
81+
# Print info about sam (version, location, …).
82+
- 'pip3 show aws-sam-cli'
83+
- 'sam --version'
84+
# Install latest version of Go (known to 'goenv')
85+
# - eval "$(goenv init -)"
86+
# - 'export PATH="$GOROOT/bin:$PATH:$GOPATH/bin"'
87+
# - '>/dev/null VERSION=$(goenv install --list | tail -n 1) && 2>/dev/null goenv install $VERSION'
88+
# - '>/dev/null goenv global $VERSION && go env -w GOPROXY=direct'
89+
# - go version
6790

6891
build:
92+
run-as: codebuild-user
93+
env:
94+
variables:
95+
HOME: /home/codebuild-user
6996
commands:
70-
- npm ci --unsafe-perm
97+
# codebuild ignores the env.variables.HOME declaration above...?
98+
- export HOME=/home/codebuild-user
99+
- npm ci
71100
- xvfb-run npm run testInteg
72101
- VCS_COMMIT_ID="${CODEBUILD_RESOLVED_SOURCE_VERSION}"
73102
- CI_BUILD_URL=$(echo $CODEBUILD_BUILD_URL | sed 's/#/%23/g')

0 commit comments

Comments
 (0)