sigs.k8s.io/cluster-api-provider-aws@v1.5.5/api/v1alpha3/awsidentity_types.go (about)

     1  /*
     2  Copyright 2021 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8  	http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package v1alpha3
    18  
    19  import (
    20  	corev1 "k8s.io/api/core/v1"
    21  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    22  )
    23  
    24  // AWSClusterIdentitySpec defines the Spec struct for AWSClusterIdentity types.
    25  type AWSClusterIdentitySpec struct {
    26  	// AllowedNamespaces is used to identify which namespaces are allowed to use the identity from.
    27  	// Namespaces can be selected either using an array of namespaces or with label selector.
    28  	// An empty AllowedNamespaces object indicates that AWSClusters can use this identity from any namespace.
    29  	// If this object is nil, no namespaces will be allowed (default behaviour, if this field is not provided)
    30  	// A namespace should be either in the NamespaceList or match with Selector to use the identity.
    31  	//
    32  	// +optional
    33  	// +nullable
    34  	AllowedNamespaces *AllowedNamespaces `json:"allowedNamespaces"`
    35  }
    36  
    37  // AllowedNamespaces is a selector of namespaces that AWSClusters can
    38  // use this ClusterPrincipal from. This is a standard Kubernetes LabelSelector,
    39  // a label query over a set of resources. The result of matchLabels and
    40  // matchExpressions are ANDed.
    41  type AllowedNamespaces struct {
    42  	// An nil or empty list indicates that AWSClusters cannot use the identity from any namespace.
    43  	//
    44  	// +optional
    45  	// +nullable
    46  	NamespaceList []string `json:"list"`
    47  
    48  	// An empty selector indicates that AWSClusters cannot use this
    49  	// AWSClusterIdentity from any namespace.
    50  	// +optional
    51  	Selector metav1.LabelSelector `json:"selector"`
    52  }
    53  
    54  // AWSRoleSpec defines the specifications for all identities based around AWS roles.
    55  type AWSRoleSpec struct {
    56  	// The Amazon Resource Name (ARN) of the role to assume.
    57  	RoleArn string `json:"roleARN"`
    58  	// An identifier for the assumed role session
    59  	SessionName string `json:"sessionName,omitempty"`
    60  	// The duration, in seconds, of the role session before it is renewed.
    61  	// +kubebuilder:validation:Minimum:=900
    62  	// +kubebuilder:validation:Maximum:=43200
    63  	DurationSeconds int32 `json:"durationSeconds,omitempty"`
    64  	// An IAM policy as a JSON-encoded string that you want to use as an inline session policy.
    65  	InlinePolicy string `json:"inlinePolicy,omitempty"`
    66  
    67  	// The Amazon Resource Names (ARNs) of the IAM managed policies that you want
    68  	// to use as managed session policies.
    69  	// The policies must exist in the same account as the role.
    70  	PolicyARNs []string `json:"policyARNs,omitempty"`
    71  }
    72  
    73  // +kubebuilder:object:root=true
    74  // +kubebuilder:resource:path=awsclusterstaticidentities,scope=Cluster,categories=cluster-api,shortName=awssi
    75  // +k8s:defaulter-gen=true
    76  
    77  // AWSClusterStaticIdentity is the Schema for the awsclusterstaticidentities API
    78  // It represents a reference to an AWS access key ID and secret access key, stored in a secret.
    79  type AWSClusterStaticIdentity struct {
    80  	metav1.TypeMeta   `json:",inline"`
    81  	metav1.ObjectMeta `json:"metadata,omitempty"`
    82  
    83  	// Spec for this AWSClusterStaticIdentity
    84  	Spec AWSClusterStaticIdentitySpec `json:"spec,omitempty"`
    85  }
    86  
    87  // +kubebuilder:object:root=true
    88  
    89  // AWSClusterStaticIdentityList contains a list of AWSClusterStaticIdentity.
    90  type AWSClusterStaticIdentityList struct {
    91  	metav1.TypeMeta `json:",inline"`
    92  	metav1.ListMeta `json:"metadata,omitempty"`
    93  	Items           []AWSClusterStaticIdentity `json:"items"`
    94  }
    95  
    96  // AWSClusterStaticIdentitySpec defines the specifications for AWSClusterStaticIdentity.
    97  type AWSClusterStaticIdentitySpec struct {
    98  	AWSClusterIdentitySpec `json:",inline"`
    99  	// Reference to a secret containing the credentials. The secret should
   100  	// contain the following data keys:
   101  	//  AccessKeyID: AKIAIOSFODNN7EXAMPLE
   102  	//  SecretAccessKey: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
   103  	//  SessionToken: Optional
   104  	SecretRef corev1.SecretReference `json:"secretRef"`
   105  }
   106  
   107  // +kubebuilder:object:root=true
   108  // +kubebuilder:resource:path=awsclusterroleidentities,scope=Cluster,categories=cluster-api,shortName=awsri
   109  // +k8s:defaulter-gen=true
   110  
   111  // AWSClusterRoleIdentity is the Schema for the awsclusterroleidentities API
   112  // It is used to assume a role using the provided sourceRef.
   113  type AWSClusterRoleIdentity struct {
   114  	metav1.TypeMeta   `json:",inline"`
   115  	metav1.ObjectMeta `json:"metadata,omitempty"`
   116  
   117  	// Spec for this AWSClusterRoleIdentity.
   118  	Spec AWSClusterRoleIdentitySpec `json:"spec,omitempty"`
   119  }
   120  
   121  // +kubebuilder:object:root=true
   122  
   123  // AWSClusterRoleIdentityList contains a list of AWSClusterRoleIdentity.
   124  type AWSClusterRoleIdentityList struct {
   125  	metav1.TypeMeta `json:",inline"`
   126  	metav1.ListMeta `json:"metadata,omitempty"`
   127  	Items           []AWSClusterRoleIdentity `json:"items"`
   128  }
   129  
   130  // AWSClusterRoleIdentitySpec defines the specifications for AWSClusterRoleIdentity.
   131  type AWSClusterRoleIdentitySpec struct {
   132  	AWSClusterIdentitySpec `json:",inline"`
   133  	AWSRoleSpec            `json:",inline"`
   134  	// A unique identifier that might be required when you assume a role in another account.
   135  	// If the administrator of the account to which the role belongs provided you with an
   136  	// external ID, then provide that value in the ExternalId parameter. This value can be
   137  	// any string, such as a passphrase or account number. A cross-account role is usually
   138  	// set up to trust everyone in an account. Therefore, the administrator of the trusting
   139  	// account might send an external ID to the administrator of the trusted account. That
   140  	// way, only someone with the ID can assume the role, rather than everyone in the
   141  	// account. For more information about the external ID, see How to Use an External ID
   142  	// When Granting Access to Your AWS Resources to a Third Party in the IAM User Guide.
   143  	// +optional
   144  	ExternalID string `json:"externalID,omitempty"`
   145  
   146  	// SourceIdentityRef is a reference to another identity which will be chained to do
   147  	// role assumption. All identity types are accepted.
   148  	SourceIdentityRef *AWSIdentityReference `json:"sourceIdentityRef,omitempty"`
   149  }
   150  
   151  // +kubebuilder:object:root=true
   152  // +kubebuilder:resource:path=awsclustercontrolleridentities,scope=Cluster,categories=cluster-api,shortName=awsci
   153  // +k8s:defaulter-gen=true
   154  
   155  // AWSClusterControllerIdentity is the Schema for the awsclustercontrolleridentities API
   156  // It is used to grant access to use Cluster API Provider AWS Controller credentials.
   157  type AWSClusterControllerIdentity struct {
   158  	metav1.TypeMeta   `json:",inline"`
   159  	metav1.ObjectMeta `json:"metadata,omitempty"`
   160  
   161  	// Spec for this AWSClusterControllerIdentity.
   162  	Spec AWSClusterControllerIdentitySpec `json:"spec,omitempty"`
   163  }
   164  
   165  // +kubebuilder:object:root=true
   166  // +k8s:defaulter-gen=true
   167  
   168  // AWSClusterControllerIdentityList contains a list of AWSClusterControllerIdentity.
   169  type AWSClusterControllerIdentityList struct {
   170  	metav1.TypeMeta `json:",inline"`
   171  	metav1.ListMeta `json:"metadata,omitempty"`
   172  	Items           []AWSClusterControllerIdentity `json:"items"`
   173  }
   174  
   175  // AWSClusterControllerIdentitySpec defines the specifications for AWSClusterControllerIdentity.
   176  type AWSClusterControllerIdentitySpec struct {
   177  	AWSClusterIdentitySpec `json:",inline"`
   178  }
   179  
   180  func init() {
   181  	SchemeBuilder.Register(
   182  		&AWSClusterStaticIdentity{},
   183  		&AWSClusterStaticIdentityList{},
   184  		&AWSClusterRoleIdentity{},
   185  		&AWSClusterRoleIdentityList{},
   186  		&AWSClusterControllerIdentity{},
   187  		&AWSClusterControllerIdentityList{},
   188  	)
   189  }