various: change OAuth and WIF auth key resolvers to take struct args
Change signature of OAuth and identityfederation auth key resolution hooks to take in structs instead of lists of args as they were getting unwieldily. Updates https://github.com/tailscale/tailscale/issues/20339 Signed-off-by: Mario Minardi <mario@tailscale.com>
This commit is contained in:
committed by
Mario Minardi
parent
3ccc7725a3
commit
c8ae72b537
+11
-2
@@ -1007,7 +1007,10 @@ func (s *Server) resolveAuthKey() (string, error) {
|
||||
if authKey == "" {
|
||||
clientSecret = s.getClientSecret()
|
||||
}
|
||||
authKey, err = resolveViaOAuth(s.shutdownCtx, clientSecret, s.AdvertiseTags)
|
||||
authKey, err = resolveViaOAuth(s.shutdownCtx, tailscale.ResolveAuthKeyArgs{
|
||||
AuthKey: clientSecret,
|
||||
Tags: s.AdvertiseTags,
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -1033,7 +1036,13 @@ func (s *Server) resolveAuthKey() (string, error) {
|
||||
return "", fmt.Errorf("audience for workload identity federation found, but client ID is empty")
|
||||
}
|
||||
}
|
||||
authKey, err = resolveViaWIF(s.shutdownCtx, s.getControlURL(), clientID, idToken, audience, s.AdvertiseTags)
|
||||
authKey, err = resolveViaWIF(s.shutdownCtx, tailscale.ResolveAuthKeyWIFArgs{
|
||||
BaseURL: s.getControlURL(),
|
||||
ClientID: clientID,
|
||||
IDToken: idToken,
|
||||
Audience: audience,
|
||||
Tags: s.AdvertiseTags,
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
+31
-31
@@ -3450,8 +3450,8 @@ func TestResolveAuthKey(t *testing.T) {
|
||||
audience string
|
||||
oauthAvailable bool
|
||||
wifAvailable bool
|
||||
resolveViaOAuth func(ctx context.Context, clientSecret string, tags []string) (string, error)
|
||||
resolveViaWIF func(ctx context.Context, baseURL, clientID, idToken, audience string, tags []string) (string, error)
|
||||
resolveViaOAuth func(ctx context.Context, args tailscale.ResolveAuthKeyArgs) (string, error)
|
||||
resolveViaWIF func(ctx context.Context, args tailscale.ResolveAuthKeyWIFArgs) (string, error)
|
||||
wantAuthKey string
|
||||
wantErr bool
|
||||
wantErrContains string
|
||||
@@ -3460,9 +3460,9 @@ func TestResolveAuthKey(t *testing.T) {
|
||||
name: "success-oauth-client-secret",
|
||||
clientSecret: "tskey-client-secret-123",
|
||||
oauthAvailable: true,
|
||||
resolveViaOAuth: func(ctx context.Context, clientSecret string, tags []string) (string, error) {
|
||||
if clientSecret != "tskey-client-secret-123" {
|
||||
return "", fmt.Errorf("unexpected client secret: %s", clientSecret)
|
||||
resolveViaOAuth: func(ctx context.Context, args tailscale.ResolveAuthKeyArgs) (string, error) {
|
||||
if args.AuthKey != "tskey-client-secret-123" {
|
||||
return "", fmt.Errorf("unexpected client secret: %s", args.AuthKey)
|
||||
}
|
||||
return "tskey-auth-via-oauth", nil
|
||||
},
|
||||
@@ -3473,7 +3473,7 @@ func TestResolveAuthKey(t *testing.T) {
|
||||
name: "fail-oauth-client-secret",
|
||||
clientSecret: "tskey-client-secret-123",
|
||||
oauthAvailable: true,
|
||||
resolveViaOAuth: func(ctx context.Context, clientSecret string, tags []string) (string, error) {
|
||||
resolveViaOAuth: func(ctx context.Context, args tailscale.ResolveAuthKeyArgs) (string, error) {
|
||||
return "", fmt.Errorf("resolution failed")
|
||||
},
|
||||
wantErrContains: "resolution failed",
|
||||
@@ -3483,12 +3483,12 @@ func TestResolveAuthKey(t *testing.T) {
|
||||
clientID: "client-id-123",
|
||||
idToken: "id-token-456",
|
||||
wifAvailable: true,
|
||||
resolveViaWIF: func(ctx context.Context, baseURL, clientID, idToken, audience string, tags []string) (string, error) {
|
||||
if clientID != "client-id-123" {
|
||||
return "", fmt.Errorf("unexpected client ID: %s", clientID)
|
||||
resolveViaWIF: func(ctx context.Context, args tailscale.ResolveAuthKeyWIFArgs) (string, error) {
|
||||
if args.ClientID != "client-id-123" {
|
||||
return "", fmt.Errorf("unexpected client ID: %s", args.ClientID)
|
||||
}
|
||||
if idToken != "id-token-456" {
|
||||
return "", fmt.Errorf("unexpected ID token: %s", idToken)
|
||||
if args.IDToken != "id-token-456" {
|
||||
return "", fmt.Errorf("unexpected ID token: %s", args.IDToken)
|
||||
}
|
||||
return "tskey-auth-via-wif", nil
|
||||
},
|
||||
@@ -3500,12 +3500,12 @@ func TestResolveAuthKey(t *testing.T) {
|
||||
clientID: "client-id-123",
|
||||
audience: "api.tailscale.com",
|
||||
wifAvailable: true,
|
||||
resolveViaWIF: func(ctx context.Context, baseURL, clientID, idToken, audience string, tags []string) (string, error) {
|
||||
if clientID != "client-id-123" {
|
||||
return "", fmt.Errorf("unexpected client ID: %s", clientID)
|
||||
resolveViaWIF: func(ctx context.Context, args tailscale.ResolveAuthKeyWIFArgs) (string, error) {
|
||||
if args.ClientID != "client-id-123" {
|
||||
return "", fmt.Errorf("unexpected client ID: %s", args.ClientID)
|
||||
}
|
||||
if audience != "api.tailscale.com" {
|
||||
return "", fmt.Errorf("unexpected ID token: %s", idToken)
|
||||
if args.Audience != "api.tailscale.com" {
|
||||
return "", fmt.Errorf("unexpected audience: %s", args.Audience)
|
||||
}
|
||||
return "tskey-auth-via-wif", nil
|
||||
},
|
||||
@@ -3517,7 +3517,7 @@ func TestResolveAuthKey(t *testing.T) {
|
||||
clientID: "client-id-123",
|
||||
idToken: "id-token-456",
|
||||
wifAvailable: true,
|
||||
resolveViaWIF: func(ctx context.Context, baseURL, clientID, idToken, audience string, tags []string) (string, error) {
|
||||
resolveViaWIF: func(ctx context.Context, args tailscale.ResolveAuthKeyWIFArgs) (string, error) {
|
||||
return "", fmt.Errorf("resolution failed")
|
||||
},
|
||||
wantErrContains: "resolution failed",
|
||||
@@ -3527,7 +3527,7 @@ func TestResolveAuthKey(t *testing.T) {
|
||||
clientID: "",
|
||||
idToken: "id-token-456",
|
||||
wifAvailable: true,
|
||||
resolveViaWIF: func(ctx context.Context, baseURL, clientID, idToken, audience string, tags []string) (string, error) {
|
||||
resolveViaWIF: func(ctx context.Context, args tailscale.ResolveAuthKeyWIFArgs) (string, error) {
|
||||
return "", fmt.Errorf("should not be called")
|
||||
},
|
||||
wantErrContains: "empty",
|
||||
@@ -3537,7 +3537,7 @@ func TestResolveAuthKey(t *testing.T) {
|
||||
clientID: "",
|
||||
audience: "api.tailscale.com",
|
||||
wifAvailable: true,
|
||||
resolveViaWIF: func(ctx context.Context, baseURL, clientID, idToken, audience string, tags []string) (string, error) {
|
||||
resolveViaWIF: func(ctx context.Context, args tailscale.ResolveAuthKeyWIFArgs) (string, error) {
|
||||
return "", fmt.Errorf("should not be called")
|
||||
},
|
||||
wantErrContains: "empty",
|
||||
@@ -3547,7 +3547,7 @@ func TestResolveAuthKey(t *testing.T) {
|
||||
clientID: "client-id-123",
|
||||
idToken: "",
|
||||
wifAvailable: true,
|
||||
resolveViaWIF: func(ctx context.Context, baseURL, clientID, idToken, audience string, tags []string) (string, error) {
|
||||
resolveViaWIF: func(ctx context.Context, args tailscale.ResolveAuthKeyWIFArgs) (string, error) {
|
||||
return "", fmt.Errorf("should not be called")
|
||||
},
|
||||
wantErrContains: "empty",
|
||||
@@ -3558,7 +3558,7 @@ func TestResolveAuthKey(t *testing.T) {
|
||||
idToken: "id-token-456",
|
||||
audience: "api.tailscale.com",
|
||||
wifAvailable: true,
|
||||
resolveViaWIF: func(ctx context.Context, baseURL, clientID, idToken, audience string, tags []string) (string, error) {
|
||||
resolveViaWIF: func(ctx context.Context, args tailscale.ResolveAuthKeyWIFArgs) (string, error) {
|
||||
return "", fmt.Errorf("should not be called")
|
||||
},
|
||||
wantErrContains: "only one of ID token and audience",
|
||||
@@ -3567,14 +3567,14 @@ func TestResolveAuthKey(t *testing.T) {
|
||||
name: "wif-skipped-oauth-succeeds",
|
||||
clientSecret: "tskey-client-secret-123",
|
||||
oauthAvailable: true,
|
||||
resolveViaOAuth: func(ctx context.Context, clientSecret string, tags []string) (string, error) {
|
||||
if clientSecret != "tskey-client-secret-123" {
|
||||
return "", fmt.Errorf("unexpected client secret: %s", clientSecret)
|
||||
resolveViaOAuth: func(ctx context.Context, args tailscale.ResolveAuthKeyArgs) (string, error) {
|
||||
if args.AuthKey != "tskey-client-secret-123" {
|
||||
return "", fmt.Errorf("unexpected client secret: %s", args.AuthKey)
|
||||
}
|
||||
return "tskey-auth-via-oauth", nil
|
||||
},
|
||||
wifAvailable: true,
|
||||
resolveViaWIF: func(ctx context.Context, baseURL, clientID, idToken, audience string, tags []string) (string, error) {
|
||||
resolveViaWIF: func(ctx context.Context, args tailscale.ResolveAuthKeyWIFArgs) (string, error) {
|
||||
return "", fmt.Errorf("should not be called")
|
||||
},
|
||||
wantAuthKey: "tskey-auth-via-oauth",
|
||||
@@ -3585,11 +3585,11 @@ func TestResolveAuthKey(t *testing.T) {
|
||||
clientID: "tskey-client-id-123",
|
||||
idToken: "",
|
||||
oauthAvailable: true,
|
||||
resolveViaOAuth: func(ctx context.Context, clientSecret string, tags []string) (string, error) {
|
||||
resolveViaOAuth: func(ctx context.Context, args tailscale.ResolveAuthKeyArgs) (string, error) {
|
||||
return "", fmt.Errorf("resolution failed")
|
||||
},
|
||||
wifAvailable: true,
|
||||
resolveViaWIF: func(ctx context.Context, baseURL, clientID, idToken, audience string, tags []string) (string, error) {
|
||||
resolveViaWIF: func(ctx context.Context, args tailscale.ResolveAuthKeyWIFArgs) (string, error) {
|
||||
return "", fmt.Errorf("should not be called")
|
||||
},
|
||||
wantErrContains: "failed",
|
||||
@@ -3613,9 +3613,9 @@ func TestResolveAuthKey(t *testing.T) {
|
||||
name: "authkey-client-secret-oauth-succeeds",
|
||||
authKey: "tskey-client-secret-123",
|
||||
oauthAvailable: true,
|
||||
resolveViaOAuth: func(ctx context.Context, clientSecret string, tags []string) (string, error) {
|
||||
if clientSecret != "tskey-client-secret-123" {
|
||||
return "", fmt.Errorf("unexpected client secret: %s", clientSecret)
|
||||
resolveViaOAuth: func(ctx context.Context, args tailscale.ResolveAuthKeyArgs) (string, error) {
|
||||
if args.AuthKey != "tskey-client-secret-123" {
|
||||
return "", fmt.Errorf("unexpected client secret: %s", args.AuthKey)
|
||||
}
|
||||
return "tskey-auth-via-oauth", nil
|
||||
},
|
||||
@@ -3626,7 +3626,7 @@ func TestResolveAuthKey(t *testing.T) {
|
||||
name: "authkey-client-secret-oauth-fails",
|
||||
authKey: "tskey-client-secret-123",
|
||||
oauthAvailable: true,
|
||||
resolveViaOAuth: func(ctx context.Context, clientSecret string, tags []string) (string, error) {
|
||||
resolveViaOAuth: func(ctx context.Context, args tailscale.ResolveAuthKeyArgs) (string, error) {
|
||||
return "", fmt.Errorf("resolution failed")
|
||||
},
|
||||
wantErrContains: "resolution failed",
|
||||
|
||||
Reference in New Issue
Block a user