mirror of
https://github.com/versity/versitygw.git
synced 2026-09-24 08:54:47 +00:00
Add support for `CreateOpenIDConnectProvider`, `GetOpenIDConnectProvider`, `ListOpenIDConnectProviders`, `DeleteOpenIDConnectProvider`, `AddClientIDToOpenIDConnectProvider`, `RemoveClientIDFromOpenIDConnectProvider`, and `UpdateOpenIDConnectProviderThumbprint` on both the internal and Vault storage backends, rounding out the standalone IAM service with the same OIDC identity provider management AWS IAM exposes. CreateOpenIDConnectProvider validates the issuer URL, enforces the client ID and per-provider client ID list limits, and accepts an optional ThumbprintList. When the caller omits ThumbprintList, the provider auto-fetches the thumbprint by opening an outbound TLS connection to the issuer URL and hashing its top-level CA certificate, matching real AWS behavior. This auto-fetch is configurable: it can be turned off with the `--disable-oidc-thumbprint-autofetch` CLI flag (or the `VGW_IAM_DISABLE_OIDC_THUMBPRINT_AUTOFETCH` environment variable) for restricted or air-gapped deployments where the IAM server shouldn't make outbound connections, in which case an omitted ThumbprintList is rejected instead. AddClientIDToOpenIDConnectProvider and RemoveClientIDFromOpenIDConnectProvider manage a provider's client ID list, and UpdateOpenIDConnectProviderThumbprint replaces its thumbprint list, all with the same length and format validation applied at creation time. Provider ARNs are derived from the issuer URL, and GetOpenIDConnectProvider and DeleteOpenIDConnectProvider resolve providers by ARN, returning NoSuchEntity when a provider doesn't exist. ListOpenIDConnectProviders returns the full set of stored providers. These actions are wired into the IAM API router and given their own XML response types under iamapi/types, with a new iamapi/internal/iamutil package handling URL validation, thumbprint fetching and normalization, and ARN construction shared across the controller methods.
123 lines
3.7 KiB
Go
123 lines
3.7 KiB
Go
// Copyright 2026 Versity Software
|
|
// This file is licensed under the Apache License, Version 2.0
|
|
// (the "License"); you may not use this file except in compliance
|
|
// with the License. You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing,
|
|
// software distributed under the License is distributed on an
|
|
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
// KIND, either express or implied. See the License for the
|
|
// specific language governing permissions and limitations
|
|
// under the License.
|
|
|
|
package integration
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
|
|
"github.com/aws/aws-sdk-go-v2/service/iam"
|
|
)
|
|
|
|
func IAMListOpenIDConnectProviders_success(s *S3Conf) error {
|
|
testName := "IAMListOpenIDConnectProviders_success"
|
|
return iamActionHandler(s, testName, func(client *iam.Client) (err error) {
|
|
before, err := listIAMOIDCProviders(client)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if requestID, ok := awsmiddleware.GetRequestIDMetadata(before.ResultMetadata); !ok || requestID == "" {
|
|
return fmt.Errorf("expected ListOpenIDConnectProviders response request id")
|
|
}
|
|
baseline := oidcProviderArnSet(before)
|
|
|
|
arnA, err := createTestOIDCProvider(client)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
arnB, err := createTestOIDCProvider(client)
|
|
if err != nil {
|
|
delErr := deleteOIDCProvider(client, arnA)
|
|
return errors.Join(err, delErr)
|
|
}
|
|
|
|
cleanup := func(arns ...string) error {
|
|
var errs error
|
|
for _, arn := range arns {
|
|
if delErr := deleteOIDCProvider(client, arn); delErr != nil {
|
|
errs = errors.Join(errs, delErr)
|
|
}
|
|
}
|
|
return errs
|
|
}
|
|
|
|
afterCreate, err := listIAMOIDCProviders(client)
|
|
if err != nil {
|
|
return errors.Join(err, cleanup(arnA, arnB))
|
|
}
|
|
createdSet := oidcProviderArnSet(afterCreate)
|
|
if _, ok := createdSet[arnA]; !ok {
|
|
return errors.Join(fmt.Errorf("expected %q in ListOpenIDConnectProviders after create", arnA), cleanup(arnA, arnB))
|
|
}
|
|
if _, ok := createdSet[arnB]; !ok {
|
|
return errors.Join(fmt.Errorf("expected %q in ListOpenIDConnectProviders after create", arnB), cleanup(arnA, arnB))
|
|
}
|
|
for arn := range baseline {
|
|
if _, ok := createdSet[arn]; !ok {
|
|
return errors.Join(fmt.Errorf("expected pre-existing %q to still be listed", arn), cleanup(arnA, arnB))
|
|
}
|
|
}
|
|
|
|
if err := deleteOIDCProvider(client, arnA); err != nil {
|
|
return errors.Join(err, cleanup(arnB))
|
|
}
|
|
|
|
afterDeleteA, err := listIAMOIDCProviders(client)
|
|
if err != nil {
|
|
return errors.Join(err, cleanup(arnB))
|
|
}
|
|
afterDeleteASet := oidcProviderArnSet(afterDeleteA)
|
|
if _, ok := afterDeleteASet[arnA]; ok {
|
|
return errors.Join(fmt.Errorf("expected %q to be absent after delete", arnA), cleanup(arnB))
|
|
}
|
|
if _, ok := afterDeleteASet[arnB]; !ok {
|
|
return errors.Join(fmt.Errorf("expected %q still listed", arnB), cleanup(arnB))
|
|
}
|
|
|
|
if err := deleteOIDCProvider(client, arnB); err != nil {
|
|
return err
|
|
}
|
|
|
|
afterDeleteB, err := listIAMOIDCProviders(client)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if _, ok := oidcProviderArnSet(afterDeleteB)[arnB]; ok {
|
|
return fmt.Errorf("expected %q to be absent after delete", arnB)
|
|
}
|
|
|
|
return nil
|
|
})
|
|
}
|
|
|
|
func listIAMOIDCProviders(client *iam.Client) (*iam.ListOpenIDConnectProvidersOutput, error) {
|
|
ctx, cancel := context.WithTimeout(context.Background(), shortTimeout)
|
|
defer cancel()
|
|
return client.ListOpenIDConnectProviders(ctx, &iam.ListOpenIDConnectProvidersInput{})
|
|
}
|
|
|
|
func oidcProviderArnSet(out *iam.ListOpenIDConnectProvidersOutput) map[string]struct{} {
|
|
set := make(map[string]struct{}, len(out.OpenIDConnectProviderList))
|
|
for _, p := range out.OpenIDConnectProviderList {
|
|
if p.Arn != nil {
|
|
set[*p.Arn] = struct{}{}
|
|
}
|
|
}
|
|
return set
|
|
}
|