Skip to content

Instantly share code, notes, and snippets.

@mamemomonga
Created June 15, 2023 18:37
Show Gist options
  • Save mamemomonga/4ca9f1b0f686cce11da937b16092cc57 to your computer and use it in GitHub Desktop.
Save mamemomonga/4ca9f1b0f686cce11da937b16092cc57 to your computer and use it in GitHub Desktop.
GitHubのOpenID Connect ID プロバイダーのサムプリントの取得
#!/bin/bash
set -eux
# GitHubのOpenID Connect ID プロバイダーのサムプリントの取得
# 参考URL
# https://docs.aws.amazon.com/ja_jp/IAM/latest/UserGuide/id_roles_providers_create_oidc_verify-thumbprint.html
# https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services
# https://qiita.com/minamijoyo/items/eac99e4b1ca0926c4310
PROVIDER_URL="https://token.actions.githubusercontent.com"
JWKS_URL=$(curl -s "$PROVIDER_URL/.well-known/openid-configuration" | jq -r .jwks_uri)
JWKS_DOMAIN=$(perl -E '$_="'$JWKS_URL'"; if(m!https://([^/]+)/!) { say $1 }')
echo 'Q' | openssl s_client -servername $JWKS_DOMAIN -showcerts -connect $JWKS_DOMAIN:443 2> /dev/null \
| perl -E 'my @certs=(); local $/; $_=<>; foreach(/(-----BEGIN CERTIFICATE-----\n.+?\n-----END CERTIFICATE-----\n)/sg) { push @certs,$1 }; print $certs[$#certs];' \
| openssl x509 -fingerprint -sha1 -noout \
| perl -E 'local $/; $_=<>; if(/Fingerprint=(.+)/) { $_=$1; s/://g; ; say lc($_); }'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment