Skip to content

Commit d265b48

Browse files
luthermonsonsl1pm4t
authored andcommitted
feat: Add IRSA support for self-managed.
Fix s3 tests
1 parent 2cbd9ad commit d265b48

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1419
-234
lines changed

api/v1beta1/awscluster_conversion.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package v1beta1
1818

1919
import (
2020
apiconversion "k8s.io/apimachinery/pkg/conversion"
21+
"sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
2122
infrav2 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
2223
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
2324
"sigs.k8s.io/controller-runtime/pkg/conversion"
@@ -62,6 +63,8 @@ func (src *AWSCluster) ConvertTo(dstRaw conversion.Hub) error {
6263
dst.Status.Bastion.CapacityReservationID = restored.Status.Bastion.CapacityReservationID
6364
}
6465
dst.Spec.Partition = restored.Spec.Partition
66+
dst.Spec.AssociateOIDCProvider = restored.Spec.AssociateOIDCProvider
67+
dst.Status.OIDCProvider = restored.Status.OIDCProvider
6568

6669
for role, sg := range restored.Status.Network.SecurityGroups {
6770
dst.Status.Network.SecurityGroups[role] = sg
@@ -218,3 +221,7 @@ func (r *AWSClusterList) ConvertFrom(srcRaw conversion.Hub) error {
218221
func Convert_v1beta2_SubnetSpec_To_v1beta1_SubnetSpec(in *infrav2.SubnetSpec, out *SubnetSpec, s apiconversion.Scope) error {
219222
return autoConvert_v1beta2_SubnetSpec_To_v1beta1_SubnetSpec(in, out, s)
220223
}
224+
225+
func Convert_v1beta2_AWSClusterStatus_To_v1beta1_AWSClusterStatus(in *v1beta2.AWSClusterStatus, out *AWSClusterStatus, scope apiconversion.Scope) error {
226+
return autoConvert_v1beta2_AWSClusterStatus_To_v1beta1_AWSClusterStatus(in, out, scope)
227+
}

api/v1beta1/s3bucket.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ import (
2121
"net"
2222

2323
"k8s.io/apimachinery/pkg/util/validation/field"
24-
25-
"sigs.k8s.io/cluster-api-provider-aws/v2/feature"
2624
)
2725

2826
// Validate validates S3Bucket fields.
@@ -37,12 +35,6 @@ func (b *S3Bucket) Validate() []*field.Error {
3735
errs = append(errs, field.Required(field.NewPath("spec", "s3Bucket", "name"), "can't be empty"))
3836
}
3937

40-
// Feature gate is not enabled but ignition is enabled then send a forbidden error.
41-
if !feature.Gates.Enabled(feature.BootstrapFormatIgnition) {
42-
errs = append(errs, field.Forbidden(field.NewPath("spec", "s3Bucket"),
43-
"can be set only if the BootstrapFormatIgnition feature gate is enabled"))
44-
}
45-
4638
if b.ControlPlaneIAMInstanceProfile == "" {
4739
errs = append(errs,
4840
field.Required(field.NewPath("spec", "s3Bucket", "controlPlaneIAMInstanceProfiles"), "can't be empty"))

api/v1beta1/zz_generated.conversion.go

Lines changed: 7 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1beta2/awscluster_spec.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package v1beta2
2+
3+
import (
4+
"k8s.io/apimachinery/pkg/util/validation/field"
5+
6+
"sigs.k8s.io/cluster-api-provider-aws/v2/feature"
7+
)
8+
9+
// Validate will validate the spec fields.
10+
func (s *AWSClusterSpec) Validate() []*field.Error {
11+
var errs field.ErrorList
12+
13+
// Check the feature gate is enabled for OIDC Provider.
14+
if s.AssociateOIDCProvider && !feature.Gates.Enabled(feature.OIDCProviderSupport) {
15+
errs = append(errs,
16+
field.Forbidden(field.NewPath("spec", "associateOIDCProvider"),
17+
"can be enabled only if the OIDCProviderSupport feature gate is enabled"),
18+
)
19+
return errs
20+
}
21+
22+
return errs
23+
}

api/v1beta2/awscluster_types.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,17 @@ type AWSClusterSpec struct {
106106
IdentityRef *AWSIdentityReference `json:"identityRef,omitempty"`
107107

108108
// S3Bucket contains options to configure a supporting S3 bucket for this
109-
// cluster - currently used for nodes requiring Ignition
110-
// (https://coreos.github.io/ignition/) for bootstrapping (requires
111-
// BootstrapFormatIgnition feature flag to be enabled).
109+
// cluster - Used for nodes requiring Ignition (https://coreos.github.io/ignition/) for bootstrapping (requires
110+
// BootstrapFormatIgnition feature flag to be enabled) and/or for storing OIDC endpoint certificates for use
111+
// with IRSA (requires OIDCProviderSupport feature flag to be enabled).
112112
// +optional
113113
S3Bucket *S3Bucket `json:"s3Bucket,omitempty"`
114+
115+
// AssociateOIDCProvider can be enabled to automatically publish the clusters Service Account issuer OIDC discovery
116+
// documents to S3, create an AWS IAM OIDC identity provider and configure it to trust the cluster issuer.
117+
// This will only work if the S3Bucket is configured properly.
118+
// +kubebuilder:default=false
119+
AssociateOIDCProvider bool `json:"associateOIDCProvider,omitempty"`
114120
}
115121

116122
// AWSIdentityKind defines allowed AWS identity types.
@@ -281,6 +287,10 @@ type AWSClusterStatus struct {
281287
FailureDomains clusterv1.FailureDomains `json:"failureDomains,omitempty"`
282288
Bastion *Instance `json:"bastion,omitempty"`
283289
Conditions clusterv1.Conditions `json:"conditions,omitempty"`
290+
291+
// OIDCProvider holds the status of the identity provider for this cluster
292+
// +optional
293+
OIDCProvider OIDCProviderStatus `json:"oidcProvider,omitempty"`
284294
}
285295

286296
// S3Bucket defines a supporting S3 bucket for the cluster, currently can be optionally used for Ignition.

api/v1beta2/awscluster_webhook.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ var (
5353
func (r *AWSCluster) ValidateCreate() (admission.Warnings, error) {
5454
var allErrs field.ErrorList
5555

56+
allErrs = append(allErrs, r.Spec.Validate()...)
5657
allErrs = append(allErrs, r.Spec.Bastion.Validate()...)
5758
allErrs = append(allErrs, r.validateSSHKeyName()...)
5859
allErrs = append(allErrs, r.Spec.AdditionalTags.Validate()...)

api/v1beta2/conditions_consts.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,11 @@ const (
192192
// S3BucketFailedReason is used when any errors occur during reconciliation of an S3 bucket.
193193
S3BucketFailedReason = "S3BucketCreationFailed"
194194
)
195+
196+
const (
197+
// OIDCProviderReadyCondition indicates that the OIDC provider has been created successfully.
198+
OIDCProviderReadyCondition = "OIDCProviderCreated"
199+
200+
// OIDCProviderReconciliationFailedReason is used if we can't reconcile the OIDC provider.
201+
OIDCProviderReconciliationFailedReason = "OIDCProviderReconciliationFailed"
202+
)

api/v1beta2/s3bucket.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ func (b *S3Bucket) Validate() []*field.Error {
3838
}
3939

4040
// Feature gate is not enabled but ignition is enabled then send a forbidden error.
41-
if !feature.Gates.Enabled(feature.BootstrapFormatIgnition) {
41+
if !feature.Gates.Enabled(feature.BootstrapFormatIgnition) && !feature.Gates.Enabled(feature.OIDCProviderSupport) {
4242
errs = append(errs, field.Forbidden(field.NewPath("spec", "s3Bucket"),
43-
"can be set only if the BootstrapFormatIgnition feature gate is enabled"))
43+
"can be set only if the BootstrapFormatIgnition or OIDCProviderSupport feature gate is enabled"))
4444
}
4545

4646
if b.PresignedURLDuration == nil {

api/v1beta2/types.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,14 @@ const (
438438
AmazonLinuxGPU EKSAMILookupType = "AmazonLinuxGPU"
439439
)
440440

441+
// OIDCProviderStatus holds the status of the AWS OIDC identity provider.
442+
type OIDCProviderStatus struct {
443+
// ARN holds the ARN of the provider
444+
ARN string `json:"arn,omitempty"`
445+
// TrustPolicy contains the boilerplate IAM trust policy to use for IRSA
446+
TrustPolicy string `json:"trustPolicy,omitempty"`
447+
}
448+
441449
// PrivateDNSName is the options for the instance hostname.
442450
type PrivateDNSName struct {
443451
// EnableResourceNameDNSAAAARecord indicates whether to respond to DNS queries for instance hostnames with DNS AAAA records.

api/v1beta2/zz_generated.deepcopy.go

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)