问题描述
创建OpenID Connect提供程序(例如AWS)时,我需要为连接器指定指纹。它是什么,我如何获得它?
例如来自How can I connect GitHub actions with AWS deployments without using a secret key?
resource "aws_iam_openid_connect_provider" "github" {
url = "https://token.actions.githubusercontent.com"
client_id_list = [
"githubactions",
]
thumbprint_list = [
"6938fd4d98bab03faadb97b34396831e3780aea1",
]
}
推荐答案
Open ID连接器的指纹是主机的公共证书的sha1哈希。要计算它,您需要获得服务的证书,然后使用openssl
这样的工具计算哈希。
考虑为GitHub操作的GitHub OpenID连接器创建一个指纹https://token.actions.githubusercontent.com(例如,因为您有兴趣将GitHub操作与AWS连接起来)。
您可以运行以下脚本来计算指纹:
% HOST=$(curl https://vstoken.actions.githubusercontent.com/.well-known/openid-configuration
| jq -r '.jwks_uri | split("/")[2]')
% echo | openssl s_client -servername $HOST -showcerts -connect $HOST:443 2> /dev/null
| sed -n -e '/BEGIN/h' -e '/BEGIN/,/END/H' -e '$x' -e '$p' | tail +2
| openssl x509 -fingerprint -noout
| sed -e "s/.*=//" -e "s/://g"
| tr "ABCDEF" "abcdef"
6938fd4d98bab03faadb97b34396831e3780aea1
这一切意味着什么?
位于https://.../.well-known/openid-configuration
的OpenID配置‘知名服务’提供了已知服务的列表,包括.jwks_uri
,如下所示:
{
"issuer": "https://token.actions.githubusercontent.com",
"jwks_uri": "https://token.actions.githubusercontent.com/.well-known/jwks",
"subject_types_supported": [
"public",
"pairwise"
],
"response_types_supported": [
"id_token"
],
"claims_supported": [
"sub",
"aud",
"exp",
"iat",
"iss",
"jti",
"nbf",
"ref",
"repository",
"repository_owner",
"run_id",
"run_number",
"run_attempt",
"actor",
"workflow",
"head_ref",
"base_ref",
"event_name",
"ref_type",
"environment",
"job_workflow_ref"
],
"id_token_signing_alg_values_supported": [
"RS256"
],
"scopes_supported": [
"openid"
]
}
在本例中,它告诉客户端Json Web Key Service URI要连接的主机位于https://token.actions.githubusercontent.com/.well-known/jwks
,但我们唯一需要的(对于SSL证书)是主机名token.actions.githubusercontent.com
。我们可以使用JQ将其通过管道传递给split("/")
函数并获得[2]
元素,在本例中它只是主机名。在此示例中,主机名与我们最初查询的主机名相同,但很可能不同。
从主机获取证书可以使用OpenSSL完成;我们使用openssl s_client -servername $HOST -showcerts -connect $HOST:443
与主机建立TLS连接并转储其证书。由于我们实际上不需要发送任何数据,因此我们通过管道输出echo
来启动会话通信。
这将产生如下所示的输出:
CONNECTED(00000005)
---
Certificate chain
0 s:/C=US/ST=California/L=San Francisco/O=GitHub, Inc./CN=*.actions.githubusercontent.com
i:/C=US/O=DigiCert Inc/CN=DigiCert TLS RSA SHA256 2020 CA1
-----BEGIN CERTIFICATE-----
MIIG9jCCBd6gAwIBAgIQCFCR4fqbkQJJbzQZsc87qzANBgkqhkiG9w0BAQsFADBP
MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMSkwJwYDVQQDEyBE
aWdpQ2VydCBUTFMgUlNBIFNIQTI1NiAyMDIwIENBMTAeFw0yMjAxMTEwMDAwMDBa
Fw0yMzAxMTEyMzU5NTlaMHsxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9y
bmlhMRYwFAYDVQQHEw1TYW4gRnJhbmNpc2NvMRUwEwYDVQQKEwxHaXRIdWIsIElu
Yy4xKDAmBgNVBAMMHyouYWN0aW9ucy5naXRodWJ1c2VyY29udGVudC5jb20wggEi
MA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCcHl5GgNgXYUI5Zz085Ar9wSiI
gdDnOkaXof2u3pcJ1138Tlz6aheVqXfJ8MOAups0LTr9j/dTHAGWKQz0qdyUdYIJ
FwiOlkmphoP+a4xVJXbdVVN7qvmfV8f0YnG5oGVyx9hDl/30JReVIYPbC8JNSiIW
2jMYnjqPu41tPclNNroW9K8gJUzT/WE4LRHohOmR1GbC1xQ8YlFS6pFs+Xuznou8
TzO8PsXRdaDe/7pYZgR/Otv5XLY5siCBraMuxtj1g4Z/Tz8d2Z+sMPIxtH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ECAjAIBgZngQwBAgMwDQYJKoZIhvcNAQELBQADggEBAHer
t3onPa679n/gWlbJhKrKW3EX3SJH/E6f7tDBpATho+vFScH90cnfjK+URSxGKqNj
OSD5nkoklEHIqdninFQFBstcHL4AGw+oWv8Zu2XHFq8hVt1hBcnpj5h232sb0HIM
ULkwKXq/YFkQZhM6LawVEWwtIwwCPgU7/uWhnOKK24fXSuhe50gG66sSmvKvhMNb
g0qZgYOrAKHKCjxMoiWJKiKnpPMzTFuMLhoClw+dj20tlQj7T9rxkTgl4ZxuYRiH
as6xuwAwapu3r9rxxZf+ingkquqTgLozZXq8oXfpf2kUCwA/d5KxTVtzhwoT0JzI
8ks5T1KESaZMkE4f97Q=
-----END CERTIFICATE-----
---
Server certificate
subject=/C=US/ST=California/L=San Francisco/O=GitHub, Inc./CN=*.actions.githubusercontent.com
issuer=/C=US/O=DigiCert Inc/CN=DigiCert TLS RSA SHA256 2020 CA1
---
No client certificate CA names sent
Server Temp Key: ECDH, P-384, 384 bits
---
SSL handshake has read 3571 bytes and written 398 bytes
---
New, TLSv1/SSLv3, Cipher is ECDHE-RSA-AES256-GCM-SHA384
Server public key is 2048 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
Protocol : TLSv1.2
Cipher : ECDHE-RSA-AES256-GCM-SHA384
Session-ID: 223C0000364B663D9E1AD1A1287F2F351C1E6D66075F206C8802B43EC6110B7A
Session-ID-ctx:
Master-Key: BBA59654810DE8EF29C2CEBB9CD1D4B886D2FF89359F24A664B31B7F71E7F1CFE719734548216CFC626EC39498EC4BE9
Start Time: 1642416883
Timeout : 7200 (sec)
Verify return code: 0 (ok)
---
从stderr
打印到stderr
的一些额外消息是我们不需要的,因此使用2> /dev/null
将其重定向到空。
tac
,一种简单的方法是向后转储它,打印出结束证书和开始证书之间的内容,然后停止;然后再次使用tac
颠倒它。由于MacOS上不存在tac
,因此可以使用原生sed
来执行此工作:
sed -n
--运行sed,但默认不打印任何输出-e '/BEGIN/h'
--当您看到Begin时,将sed保留缓冲区设置到行-e '/BEGIN/,/END/H'
--对于BEGIN和END之间的所有行,将它们附加到保留缓冲区(h
设置值,H
附加,但我们在这里以两个BEGIN
结束)-e '$x' -e '$p'
--当您到达文件末尾时($
),将保留缓冲区交换为输出缓冲区(x
),然后打印它(p
)
tail +2
--从第2行开始打印,以避免从上面重复的BEGIN
。openssl x509 -fingerprint -noout
--将输出通过管道传输到openssl
,它将提供SHA1 Fingerprint= 69:38:FD:4D:98:BA:B0:3F:AA:DB:97:B3:43:96:83:1E:37:80:AE:A1
形式的指纹结果sed -e "s/.*=//" -e "s/://g"
--删除=
之前的所有内容,然后从输出中删除所有冒号(:
)tr "ABCDEF" "abcdef"
--将A
替换为a
,B
替换为b
等(技术上不需要,但使其看起来更少呼喊。
其最终结果6938fd4d98bab03faadb97b34396831e3780aea1
是在配置OpenID客户端时可以使用的指纹,例如How can I connect GitHub actions with AWS deployments without using a secret key?
a031c46782e6e6c662c2c87c76da9aa62ccabd8e
更改至6938fd4d98bab03faadb97b34396831e3780aea1
这篇关于如何计算OpenID Connect服务器的指纹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!