This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathentrypoint.sh
executable file
·160 lines (133 loc) · 4.07 KB
/
entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/bin/sh -l
setup() {
echo "---------- Preparing pico de gallo SLSA ----------"
REPO_NAME="${INPUT_REPO_NAME##*/}"
if [ -z "$REPO_NAME" ]; then
echo "REPO_NAME is empty"
exit 1
fi
if [ -z "$INPUT_REGISTRY" ]; then
echo "INPUT_REGISTRY is empty"
exit 1
fi
if [ -n "$INPUT_DOCKER_USER" ]; then
export GITHUB_ACTOR="$INPUT_DOCKER_USER"
fi
if [ -z "$GITHUB_ACTOR" ]; then
echo "GITHUB_ACTOR is not set. Please set it to your GitHub username."
exit 1
fi
if [ -n "$INPUT_IMAGE" ]; then
export IMAGE="$INPUT_IMAGE"
fi
if [ -z "$INPUT_IMAGE_DIGEST" ] || [ -z "$IMAGE" ]; then
echo "IMAGE and IMAGE_DIGEST is not set. Please set it."
exit 1
fi
export IMAGE="$IMAGE@$INPUT_IMAGE_DIGEST"
if [ -z "$INPUT_GITHUB_CONTEXT" ] || [ -z "$INPUT_RUNNER_CONTEXT" ]; then
echo "GITHUB_CONTEXT and RUNNER_CONTEXT are required"
exit 1
fi
if [ "$INPUT_VERIFY_ATTESTATION" = "false" ] && [ -z "$INPUT_KEY" ]; then
echo "When running keyless salsa you must verify the attestation. Please set the verify_attestation flag to 'true'.
(This is also the default value, and may instead be omitted)."
exit 1
fi
GITHUB=$(echo "${INPUT_GITHUB_CONTEXT}" | base64 -w 0) &&
RUNNER=$(echo "${INPUT_RUNNER_CONTEXT}" | base64 -w 0) &&
ENVS=$(jq -n env | base64 -w 0)
exportCosignEnvironment
exportGithubToken
export JAVA_HOME=/opt/java/openjdk
}
exportGithubToken() {
if [ -n "$INPUT_GITHUB_TOKEN" ]; then
if [ -n "$INPUT_TOKEN_KEY_PATTERN" ]; then
export "$INPUT_TOKEN_KEY_PATTERN"="$INPUT_GITHUB_TOKEN"
else
export GITHUB_TOKEN="$INPUT_GITHUB_TOKEN"
fi
else
export GITHUB_TOKEN
fi
}
exportCosignEnvironment() {
if [ -n "$COSIGN_EXPERIMENTAL" ]; then
export COSIGN_EXPERIMENTAL
fi
if [ -n "$COSIGN_REPOSITORY" ]; then
export COSIGN_REPOSITORY
fi
}
loginDocker() {
echo "---------- Logging in to Docker registry: $INPUT_REGISTRY ----------"
if [ -n "$INPUT_REGISTRY_ACCESS_TOKEN" ]; then
echo "$INPUT_REGISTRY_ACCESS_TOKEN" | docker login "$INPUT_REGISTRY" -u "$GITHUB_ACTOR" --password-stdin
else
echo "$GITHUB_TOKEN" | docker login "$INPUT_REGISTRY" -u "$GITHUB_ACTOR" --password-stdin
fi
}
logoutDocker() {
echo "---------- Logging out from Docker registry: $INPUT_REGISTRY ----------"
docker logout "$INPUT_REGISTRY"
}
scan() {
echo "---------- Running Salsa scan for deps ----------" &&
salsa scan \
--repo "$REPO_NAME" \
--build-context "$GITHUB" \
--runner-context "$RUNNER" \
--env-context "$ENVS" \
--subDir "$INPUT_REPO_SUB_DIR" \
--mvn-opts "$INPUT_MVN_OPTS" \
--build-started-on "$INPUT_BUILD_STARTED_ON" \
--remote-run
}
attest() {
echo "---------- Creating and Uploading Salsa attestation ----------" &&
salsa attest \
--repo "$REPO_NAME" \
--subDir "$INPUT_REPO_SUB_DIR" \
--remote-run \
--identity-token "$INPUT_IDENTITY_TOKEN" \
--key "$INPUT_KEY" \
"$IMAGE"
}
attestVerify() {
echo "---------- Verifying Salsa attestation ----------" &&
salsa attest \
--verify \
--repo "$REPO_NAME" \
--subDir "$INPUT_REPO_SUB_DIR" \
--remote-run \
--key "$INPUT_KEY" \
"$IMAGE"
}
runSalsa() {
echo "---------- Running Salsa for repository: $REPO_NAME ----------"
if [ "$INPUT_VERIFY_ATTESTATION" = "false" ]; then
scan && attest
elif [ "$INPUT_VERIFY_ATTESTATION" = "true" ]; then
scan && attest && attestVerify
fi
}
cleanUpGoogle() {
echo "---------- Clean up Google Cloud stuff ----------"
if
[ -n "$GOOGLE_APPLICATION_CREDENTIALS" ] ||
[ -n "$CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE" ] ||
[ -n "$GOOGLE_GHA_CREDS_PATH" ]
then
rm -rvf "$GOOGLE_APPLICATION_CREDENTIALS" "$CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE" "$GOOGLE_GHA_CREDS_PATH"
fi
}
setOutput() {
echo "---------- Setting output ----------"
{
echo "provenance_file_path=$REPO_NAME.provenance"
echo "raw_file_path=$REPO_NAME.raw.txt"
} >>"$GITHUB_OUTPUT"
}
setup && loginDocker && runSalsa && logoutDocker && setOutput
cleanUpGoogle