Skip to content

Commit 59a0a83

Browse files
authored
ci: run-as unprivileged user #3564
ref f53186e
1 parent 6a66f7f commit 59a0a83

File tree

2 files changed

+33
-13
lines changed

2 files changed

+33
-13
lines changed

buildspec/linuxIntegrationTests.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
version: 0.2
22

3+
# Run unprivileged for most phases (except those marked "run-as: root").
4+
run-as: codebuild-user
5+
36
env:
47
variables:
58
# Implicitly passed by the AWS automation pipeline:
69
# VSCODE_TEST_VERSION
710
# GITHUB_READONLY_TOKEN
8-
AWS_TOOLKIT_TEST_USER_DIR: '/tmp/'
911
AWS_TOOLKIT_TEST_NO_COLOR: '1'
1012
NO_COVERAGE: 'true'
1113
# Suppress noisy apt-get/dpkg warnings like "debconf: unable to initialize frontend: Dialog").
1214
DEBIAN_FRONTEND: 'noninteractive'
1315

1416
phases:
1517
install:
18+
run-as: root
1619
runtime-versions:
1720
nodejs: 16
1821
dotnet: 6.0
@@ -43,10 +46,9 @@ phases:
4346
# Prepare env for unprivileged user.
4447
#
4548
- |
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 .
49+
# adduser --gecos GECOS --disabled-password toolkit-user
50+
mkdir -p ~codebuild-user
51+
chown -R codebuild-user:codebuild-user /tmp ~codebuild-user .
5052
chmod +x ~codebuild-user
5153
ls -ld ~codebuild-user
5254
# Add user to "docker" group.
@@ -56,12 +58,11 @@ phases:
5658
- chmod 666 /var/run/docker.sock
5759

5860
pre_build:
59-
run-as: codebuild-user
6061
env:
6162
variables:
6263
HOME: /home/codebuild-user
6364
commands:
64-
# codebuild ignores the env.variables.HOME declaration above...?
65+
# CodeBuild ignores the env.variables.HOME declaration above? :(
6566
- export HOME=/home/codebuild-user
6667
- bash buildspec/setup-github-token.sh
6768
# If present, log into CodeArtifact. Provides a nice safety net in case NPM is down.
@@ -89,12 +90,11 @@ phases:
8990
# - go version
9091

9192
build:
92-
run-as: codebuild-user
9393
env:
9494
variables:
9595
HOME: /home/codebuild-user
9696
commands:
97-
# codebuild ignores the env.variables.HOME declaration above...?
97+
# CodeBuild ignores the env.variables.HOME declaration above? :(
9898
- export HOME=/home/codebuild-user
9999
- npm ci
100100
- xvfb-run npm run testInteg

buildspec/linuxTests.yml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
version: 0.2
22

3+
# Run unprivileged for most phases (except those marked "run-as: root").
4+
run-as: codebuild-user
5+
36
env:
47
variables:
58
AWS_TOOLKIT_TEST_NO_COLOR: '1'
69

710
phases:
811
install:
12+
run-as: root
913
runtime-versions:
1014
nodejs: 16
1115

@@ -14,9 +18,22 @@ phases:
1418
- '>/dev/null apt-get -yqq update'
1519
# Dependencies for running vscode.
1620
- '>/dev/null apt-get -yqq install libatk1.0-0 libgtk-3-dev libxss1 xvfb libasound2 libasound2-plugins'
21+
#
22+
# Prepare env for unprivileged user.
23+
#
24+
- |
25+
mkdir -p ~codebuild-user
26+
chown -R codebuild-user:codebuild-user /tmp ~codebuild-user .
27+
chmod +x ~codebuild-user
28+
ls -ld ~codebuild-user
1729
1830
pre_build:
31+
env:
32+
variables:
33+
HOME: /home/codebuild-user
1934
commands:
35+
# CodeBuild ignores the env.variables.HOME declaration above? :(
36+
- export HOME=/home/codebuild-user
2037
# If present, log into CodeArtifact. Provides a nice safety net in case NPM is down.
2138
# Should only affect tests run through IDEs team-hosted CodeBuild.
2239
- |
@@ -27,13 +44,16 @@ phases:
2744
echo "CodeArtifact connection failed. Falling back to npm"
2845
fi
2946
fi
30-
- npm ci --unsafe-perm
47+
- npm ci
3148

3249
build:
50+
env:
51+
variables:
52+
HOME: /home/codebuild-user
3353
commands:
34-
- mkdir -p /home/codebuild-user
35-
- chown -R codebuild-user:codebuild-user /tmp /home/codebuild-user .
36-
- su codebuild-user -c "xvfb-run npm test --silent"
54+
# CodeBuild ignores the env.variables.HOME declaration above? :(
55+
- export HOME=/home/codebuild-user
56+
- xvfb-run npm test --silent
3757
- VCS_COMMIT_ID="${CODEBUILD_RESOLVED_SOURCE_VERSION}"
3858
- CI_BUILD_URL=$(echo $CODEBUILD_BUILD_URL | sed 's/#/%23/g') # Encode `#` in the URL because otherwise the url is clipped in the Codecov.io site
3959
- CI_BUILD_ID="${CODEBUILD_BUILD_ID}"

0 commit comments

Comments
 (0)