Skip to content

Commit a6758e6

Browse files
committed
actions/deploy: auto-renew github token instead of using single-use token
Take two, now with correct masks and variables.
1 parent 50752be commit a6758e6

File tree

3 files changed

+10
-15
lines changed

3 files changed

+10
-15
lines changed

actions/deploy/entrypoint.sh

+9-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
if [ -n "$APIKEY" ]; then
55
echo "::add-mask::$APIKEY"
66
fi
7+
8+
if [ -n "$ACTIONS_ID_TOKEN_REQUEST_URL" ]; then
9+
echo "::add-mask::$ACTIONS_ID_TOKEN_REQUEST_URL"
10+
fi
11+
712
if [ -n "$ACTIONS_ID_TOKEN_REQUEST_TOKEN" ]; then
813
echo "::add-mask::$ACTIONS_ID_TOKEN_REQUEST_TOKEN"
914
fi
@@ -65,12 +70,10 @@ if [ -z "$APIKEY" ]; then
6570
exit 1
6671
fi
6772

68-
payload=$(curl -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=hookd")
69-
jwt=$(echo "$payload" | jq -r '.value')
70-
export GITHUB_TOKEN="$jwt"
71-
72-
#export GITHUB_TOKEN_REQUEST_TOKEN="$ACTIONS_ID_TOKEN_REQUEST_TOKEN"
73-
#export GITHUB_TOKEN_REQUEST_URL="$ACTIONS_ID_TOKEN_REQUEST_URL"
73+
export GITHUB_TOKEN_URL="$ACTIONS_ID_TOKEN_REQUEST_URL"
74+
echo "::add-mask::$GITHUB_TOKEN_URL"
75+
export GITHUB_BEARER_TOKEN="$ACTIONS_ID_TOKEN_REQUEST_TOKEN"
76+
echo "::add-mask::$GITHUB_BEARER_TOKEN"
7477
else
7578
echo "::notice ::APIKEY IS DEPRECATED, PLEASE USE WORKLOAD IDENTITY, For more info see https://doc.nais.io/build/how-to/build-and-deploy and/or https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs"
7679
fi

pkg/deployclient/config.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ type Config struct {
1919
DeployServerURL string
2020
DryRun bool
2121
Environment string
22-
GitHubToken string
2322
GitHubTokenURL string
2423
GitHubBearerToken string
2524
GrpcAuthentication bool
@@ -54,7 +53,6 @@ func InitConfig(cfg *Config) {
5453
flag.StringVar(&cfg.DeployServerURL, "deploy-server", getEnv("DEPLOY_SERVER", DefaultDeployServer), "URL to API server. (env DEPLOY_SERVER)")
5554
flag.BoolVar(&cfg.DryRun, "dry-run", getEnvBool("DRY_RUN", false), "Run templating, but don't actually make any requests. (env DRY_RUN)")
5655
flag.StringVar(&cfg.Environment, "environment", os.Getenv("ENVIRONMENT"), "Environment for GitHub deployment. Autodetected from nais.yaml if not specified. (env ENVIRONMENT)")
57-
flag.StringVar(&cfg.GitHubToken, "github-token", os.Getenv("GITHUB_TOKEN"), "Deprecated. Use 'github-token-url' and 'github-bearer-token' instead. Github JWT. (env GITHUB_TOKEN)")
5856
flag.StringVar(&cfg.GitHubTokenURL, "github-token-url", os.Getenv("GITHUB_TOKEN_URL"), "URL for requesting GitHub id_token. (env GITHUB_TOKEN_URL)")
5957
flag.StringVar(&cfg.GitHubBearerToken, "github-bearer-token", os.Getenv("GITHUB_BEARER_TOKEN"), "Bearer token for use when requesting GitHub id_token. (env GITHUB_BEARER_TOKEN)")
6058
flag.BoolVar(&cfg.GrpcAuthentication, "grpc-authentication", getEnvBool("GRPC_AUTHENTICATION", true), "Use team API key to authenticate requests. (env GRPC_AUTHENTICATION)")
@@ -143,7 +141,7 @@ func (cfg *Config) Validate() error {
143141
return ErrClusterRequired
144142
}
145143

146-
githubAuth := len(cfg.GitHubToken) > 0 || (len(cfg.GitHubTokenURL) > 0 && len(cfg.GitHubBearerToken) > 0)
144+
githubAuth := len(cfg.GitHubTokenURL) > 0 && len(cfg.GitHubBearerToken) > 0
147145
if len(cfg.APIKey) == 0 && !githubAuth {
148146
return ErrAuthRequired
149147
}

pkg/deployclient/grpc.go

-6
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@ func NewGrpcConnection(cfg Config) (*grpc.ClientConn, error) {
3030
TokenURL: cfg.GitHubTokenURL,
3131
Team: cfg.Team,
3232
}
33-
} else if cfg.GitHubToken != "" {
34-
interceptor = &auth_interceptor.JWTInterceptor{
35-
JWT: cfg.GitHubToken,
36-
RequireTLS: cfg.GrpcUseTLS,
37-
Team: cfg.Team,
38-
}
3933
} else {
4034
decoded, err := hex.DecodeString(cfg.APIKey)
4135
if err != nil {

0 commit comments

Comments
 (0)