mirror of
https://github.com/storytold/irsa-manager.git
synced 2026-10-09 00:09:43 +00:00
fix IdP interface
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package selfhosted
|
||||
|
||||
import "context"
|
||||
|
||||
type OIDCIdProvider interface {
|
||||
Discovery() ([]byte, error)
|
||||
JWK() ([]byte, error)
|
||||
@@ -8,5 +10,5 @@ type OIDCIdProvider interface {
|
||||
|
||||
type OIDCIdPCreator interface {
|
||||
CreateStorage() error
|
||||
Upload(o OIDCIdProvider) error
|
||||
Upload(ctx context.Context, o OIDCIdProvider) error
|
||||
}
|
||||
|
||||
@@ -7,9 +7,10 @@ import (
|
||||
"github.com/kkb0318/irsa-manager/internal/selfhosted"
|
||||
)
|
||||
|
||||
type MyIdProvider struct {
|
||||
type IdProvider struct {
|
||||
jwk *selfhosted.JWK
|
||||
issuerHostPath string
|
||||
jwksFileName string
|
||||
}
|
||||
|
||||
type OIDCDiscoveryConfiguration struct {
|
||||
@@ -22,10 +23,10 @@ type OIDCDiscoveryConfiguration struct {
|
||||
ClaimsSupported []string `json:"claims_supported"`
|
||||
}
|
||||
|
||||
func (p *MyIdProvider) Discovery() ([]byte, error) {
|
||||
func (p *IdProvider) Discovery() ([]byte, error) {
|
||||
oidcConfig := OIDCDiscoveryConfiguration{
|
||||
Issuer: fmt.Sprintf("https://%s/", p.issuerHostPath),
|
||||
JWKSURI: fmt.Sprintf("https://%s/keys.json", p.issuerHostPath),
|
||||
JWKSURI: fmt.Sprintf("https://%s/%s", p.issuerHostPath, p.jwksFileName),
|
||||
AuthorizationEndpoint: "urn:kubernetes:programmatic_authorization",
|
||||
ResponseTypesSupported: []string{"id_token"},
|
||||
SubjectTypesSupported: []string{"public"},
|
||||
@@ -39,7 +40,7 @@ func (p *MyIdProvider) Discovery() ([]byte, error) {
|
||||
return jsonData, nil
|
||||
}
|
||||
|
||||
func (p *MyIdProvider) JWK() ([]byte, error) {
|
||||
func (p *IdProvider) JWK() ([]byte, error) {
|
||||
jsonData, err := json.MarshalIndent(p.jwk.GetKeys(), "", " ")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -47,10 +48,10 @@ func (p *MyIdProvider) JWK() ([]byte, error) {
|
||||
return jsonData, nil
|
||||
}
|
||||
|
||||
func (p *MyIdProvider) Endpoint() []byte {
|
||||
return []byte{}
|
||||
func (p *IdProvider) Endpoint() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func NewMyIdProvider(jwk *selfhosted.JWK, issuerHostPath string) *MyIdProvider {
|
||||
return &MyIdProvider{jwk, issuerHostPath}
|
||||
func NewIdProvider(jwk *selfhosted.JWK, issuerHostPath, jwksFileName string) *IdProvider {
|
||||
return &IdProvider{jwk, issuerHostPath, jwksFileName}
|
||||
}
|
||||
|
||||
@@ -16,17 +16,11 @@ type S3IdPCreator struct {
|
||||
|
||||
// NewS3IdPCreator initializes a new instance of S3IdPCreator with the specified AWS region and bucket name.
|
||||
// This function attempts to create an AWS client configured for the specified region.
|
||||
func NewS3IdPCreator(region, bucketName string) (*S3IdPCreator, error) {
|
||||
ctx := context.Background()
|
||||
awsConfig, err := client.NewAwsClient(ctx, region)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to load SDK config, %w", err)
|
||||
}
|
||||
func NewS3IdPCreator(awsConfig *client.AwsConfig, bucketName string) (*S3IdPCreator, error) {
|
||||
s3Client := awsConfig.S3Cient(bucketName)
|
||||
return &S3IdPCreator{s3Client}, nil
|
||||
}
|
||||
|
||||
|
||||
// CreateStorage creates an S3 bucket
|
||||
func (s *S3IdPCreator) CreateStorage() error {
|
||||
err := s.s3Client.CreateBucket(context.TODO())
|
||||
@@ -39,18 +33,26 @@ func (s *S3IdPCreator) CreateStorage() error {
|
||||
// Upload uploads the OIDC provider's discovery configuration and JSON Web Key Set (JWKS) to the specified AWS S3 bucket.
|
||||
// This method is responsible for uploading the necessary OIDC configuration files to S3, making them accessible for OIDC clients.
|
||||
func (s *S3IdPCreator) Upload(ctx context.Context, o selfhosted.OIDCIdProvider) error {
|
||||
err := s.s3Client.PutObject(ctx,
|
||||
discovery, err := o.Discovery()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
err = s.s3Client.PutObject(ctx,
|
||||
CONFIGURATION_PATH,
|
||||
o.Discovery(),
|
||||
discovery,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to upload discovery document, %w", err)
|
||||
}
|
||||
|
||||
// Uplaod JWK
|
||||
jwk, err := o.JWK()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
err = s.s3Client.PutObject(ctx,
|
||||
"keys.json",
|
||||
o.JWK(),
|
||||
jwk,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to upload JWK, %w", err)
|
||||
|
||||
Reference in New Issue
Block a user