mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
identity: default to RS256 for new workload ids (#18882)
OIDC mandates the support of the RS256 signing algorithm so in order to maximize workload identity's usefulness this change switches from using the EdDSA signing algorithm to RS256. Old keys will continue to use EdDSA but new keys will use RS256. The EdDSA generation code was left in place because it's fast and cheap and I'm not going to lie I hope we get to use it again. **Test Updates** Most of our Variables and Keyring tests had a subtle assumption in them that the keyring would be initialized by the time the test server had elected a leader. ed25519 key generation is so fast that the fact that it was happening asynchronously with server startup didn't seem to cause problems. Sadly rsa key generation is so slow that basically all of these tests failed. I added a new `testutil.WaitForKeyring` helper to replace `testutil.WaitForLeader` in cases where the keyring must be initialized before the test may continue. However this is mostly used in the `nomad/` package. In the `api` and `command/agent` packages I decided to switch their helpers to wait for keyring initialization by default. This will slow down tests a bit, but allow those packages to not be as concerned with subtle server readiness details. On my machine rsa key generation takes 63ms, so hopefully the difference isn't significant on CI runners. **TODO** - Docs and changelog entries. - Upgrades - right now upgrades won't get RS256 keys until their root key rotates either manually or after ~30 days. - Observability - I'm not sure there's a way for operators to see if they're using EdDSA or RS256 unless they inspect a key. The JWKS endpoint can be inspected to see if EdDSA will be used for new identities, but it doesn't technically define which key is active. If upgrades can be fixed to automatically rotate keys, we probably don't need to worry about this. **Requiem for ed25519** When workload identities were first implemented we did not immediately consider OIDC compliance. Consul, Vault, and many other third parties support JWT auth methods without full OIDC compliance. For the machine<-->machine use cases workload identity is intended to fulfill, OIDC seemed like a bigger risk than asset. EdDSA/ed25519 is the signing algorithm we chose for workload identity JWTs because of all these lovely properties: 1. Deterministic keys that can be derived from our preexisting root keys. This was perhaps the biggest factor since we already had a root encryption key around from which we could derive a signing key. 2. Wonderfully compact: 64 byte private key, 32 byte public key, 64 byte signatures. Just glorious. 3. No parameters. No choices of encodings. It's all well-defined by [RFC 8032](https://datatracker.ietf.org/doc/html/rfc8032). 4. Fastest performing signing algorithm! We don't even care that much about the performance of our chosen algorithm, but what a free bonus! 5. Arguably one of the most secure signing algorithms widely available. Not just from a cryptanalysis perspective, but from an API and usage perspective too. Life was good with ed25519, but sadly it could not last. [IDPs](https://en.wikipedia.org/wiki/Identity_provider), such as AWS's IAM OIDC Provider, love OIDC. They have OIDC implemented for humans, so why not reuse that OIDC support for machines as well? Since OIDC mandates RS256, many implementations don't bother implementing other signing algorithms (or at least not advertising their support). A quick survey of OIDC Discovery endpoints revealed only 2 out of 10 OIDC providers advertised support for anything other than RS256: - [PayPal](https://www.paypalobjects.com/.well-known/openid-configuration) supports HS256 - [Yahoo](https://api.login.yahoo.com/.well-known/openid-configuration) supports ES256 RS256 only: - [GitHub](https://token.actions.githubusercontent.com/.well-known/openid-configuration) - [GitLab](https://gitlab.com/.well-known/openid-configuration) - [Google](https://accounts.google.com/.well-known/openid-configuration) - [Intuit](https://developer.api.intuit.com/.well-known/openid_configuration) - [Microsoft](https://login.microsoftonline.com/fabrikamb2c.onmicrosoft.com/v2.0/.well-known/openid-configuration) - [SalesForce](https://login.salesforce.com/.well-known/openid-configuration) - [SimpleLogin (acquired by ProtonMail)](https://app.simplelogin.io/.well-known/openid-configuration/) - [TFC](https://app.terraform.io/.well-known/openid-configuration)
This commit is contained in:
@@ -248,7 +248,7 @@ func NewTestServer(t testing.T, cb ServerConfigCallback) *TestServer {
|
||||
|
||||
// Wait for the server to be ready
|
||||
if nomadConfig.Server.Enabled && nomadConfig.Server.BootstrapExpect != 0 {
|
||||
server.waitForLeader()
|
||||
server.waitForServers()
|
||||
} else {
|
||||
server.waitForAPI()
|
||||
}
|
||||
@@ -344,14 +344,14 @@ func (s *TestServer) waitForAPI() {
|
||||
})
|
||||
}
|
||||
|
||||
// waitForLeader waits for the Nomad server's HTTP API to become
|
||||
// available, and then waits for a known leader and an index of
|
||||
// 1 or more to be observed to confirm leader election is done.
|
||||
func (s *TestServer) waitForLeader() {
|
||||
// waitForServers waits for the Nomad server's HTTP API to become available,
|
||||
// and then waits for the keyring to be intialized. This implies a leader has
|
||||
// been elected and Raft writes have occurred.
|
||||
func (s *TestServer) waitForServers() {
|
||||
WaitForResult(func() (bool, error) {
|
||||
// Query the API and check the status code
|
||||
// Using this endpoint as it is does not have restricted access
|
||||
resp, err := s.HTTPClient.Get(s.url("/v1/status/leader"))
|
||||
resp, err := s.HTTPClient.Get(s.url("/.well-known/jwks.json"))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -360,6 +360,16 @@ func (s *TestServer) waitForLeader() {
|
||||
return false, err
|
||||
}
|
||||
|
||||
jwks := struct {
|
||||
Keys []interface{} `json:"keys"`
|
||||
}{}
|
||||
if err := json.NewDecoder(resp.Body).Decode(&jwks); err != nil {
|
||||
return false, fmt.Errorf("error decoding jwks response: %w", err)
|
||||
}
|
||||
if len(jwks.Keys) == 0 {
|
||||
return false, fmt.Errorf("no keys found")
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
defer s.Stop()
|
||||
|
||||
@@ -169,6 +169,24 @@ func WaitForLeaders(t testing.TB, rpcs ...rpcFn) string {
|
||||
return leader
|
||||
}
|
||||
|
||||
// WaitForKeyring blocks until the keyring is initialized.
|
||||
func WaitForKeyring(t testing.TB, rpc rpcFn, region string) {
|
||||
t.Helper()
|
||||
args := structs.GenericRequest{
|
||||
QueryOptions: structs.QueryOptions{
|
||||
Namespace: "default",
|
||||
Region: region,
|
||||
},
|
||||
}
|
||||
reply := structs.KeyringListPublicResponse{}
|
||||
WaitForResult(func() (bool, error) {
|
||||
err := rpc("Keyring.ListPublic", &args, &reply)
|
||||
return len(reply.PublicKeys) > 0, err
|
||||
}, func(err error) {
|
||||
t.Fatalf("timed out waiting for keyring to initialize: %v", err)
|
||||
})
|
||||
}
|
||||
|
||||
// WaitForClient blocks until the client can be found
|
||||
func WaitForClient(t testing.TB, rpc rpcFn, nodeID string, region string) {
|
||||
t.Helper()
|
||||
|
||||
Reference in New Issue
Block a user