Skip to content

Commit 4e497c7

Browse files
committed
feat: add fields to support binary authorization
Signed-off-by: Carlos Salas <[email protected]>
1 parent a1e46dd commit 4e497c7

File tree

6 files changed

+62
-0
lines changed

6 files changed

+62
-0
lines changed

cloud/services/container/clusters/reconcile.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,15 +267,20 @@ func (s *Service) createCluster(ctx context.Context, log *logr.Logger) error {
267267
ReleaseChannel: &containerpb.ReleaseChannel{
268268
Channel: convertToSdkReleaseChannel(s.scope.GCPManagedControlPlane.Spec.ReleaseChannel),
269269
},
270+
BinaryAuthorization: &containerpb.BinaryAuthorization{
271+
EvaluationMode: convertToSdkBinaryAuthorizationEvaluationMode(s.scope.GCPManagedControlPlane.Spec.BinaryAuthorization),
272+
},
270273
ControlPlaneEndpointsConfig: &containerpb.ControlPlaneEndpointsConfig{
271274
IpEndpointsConfig: &containerpb.ControlPlaneEndpointsConfig_IPEndpointsConfig{
272275
AuthorizedNetworksConfig: convertToSdkMasterAuthorizedNetworksConfig(s.scope.GCPManagedControlPlane.Spec.MasterAuthorizedNetworksConfig),
273276
},
274277
},
275278
}
279+
276280
if initialClusterVersionFromSpec := s.scope.GetControlPlaneVersion(); initialClusterVersionFromSpec != nil {
277281
cluster.InitialClusterVersion = convertToSdkMasterVersion(*initialClusterVersionFromSpec)
278282
}
283+
279284
if s.scope.GCPManagedControlPlane.Spec.ClusterNetwork != nil {
280285
cn := s.scope.GCPManagedControlPlane.Spec.ClusterNetwork
281286
if cn.UseIPAliases {
@@ -284,16 +289,19 @@ func (s *Service) createCluster(ctx context.Context, log *logr.Logger) error {
284289
cluster.IpAllocationPolicy.ClusterIpv4CidrBlock = cn.Pod.CidrBlock
285290
cluster.IpAllocationPolicy.ServicesIpv4CidrBlock = cn.Service.CidrBlock
286291
}
292+
287293
if cn.PrivateCluster != nil {
288294
cluster.PrivateClusterConfig = &containerpb.PrivateClusterConfig{}
289295

290296
enablePublicEndpoint := !cn.PrivateCluster.EnablePrivateEndpoint
291297
cluster.ControlPlaneEndpointsConfig.IpEndpointsConfig.EnablePublicEndpoint = &enablePublicEndpoint
298+
292299
if cn.PrivateCluster.EnablePrivateEndpoint {
293300
cluster.ControlPlaneEndpointsConfig.IpEndpointsConfig.AuthorizedNetworksConfig = &containerpb.MasterAuthorizedNetworksConfig{
294301
Enabled: true,
295302
}
296303
}
304+
297305
cluster.NetworkConfig.DefaultEnablePrivateNodes = &cn.PrivateCluster.EnablePrivateNodes
298306

299307
cluster.PrivateClusterConfig.MasterIpv4CidrBlock = cn.PrivateCluster.ControlPlaneCidrBlock
@@ -442,6 +450,22 @@ func convertToSdkMasterAuthorizedNetworksConfig(config *infrav1exp.MasterAuthori
442450
}
443451
}
444452

453+
// convertToSdkBinaryAuthorizationEvaluationMode converts the BinaryAuthorization string to the SDK int32 value.
454+
func convertToSdkBinaryAuthorizationEvaluationMode(mode *infrav1exp.BinaryAuthorization) containerpb.BinaryAuthorization_EvaluationMode {
455+
if mode == nil {
456+
return containerpb.BinaryAuthorization_EVALUATION_MODE_UNSPECIFIED
457+
}
458+
459+
switch *mode {
460+
case infrav1exp.EvaluationModeDisabled:
461+
return containerpb.BinaryAuthorization_DISABLED
462+
case infrav1exp.EvaluationModeProjectSingletonPolicyEnforce:
463+
return containerpb.BinaryAuthorization_PROJECT_SINGLETON_POLICY_ENFORCE
464+
default:
465+
return containerpb.BinaryAuthorization_EVALUATION_MODE_UNSPECIFIED
466+
}
467+
}
468+
445469
func (s *Service) checkDiffAndPrepareUpdate(existingCluster *containerpb.Cluster, log *logr.Logger) (bool, *containerpb.UpdateClusterRequest) {
446470
log.V(4).Info("Checking diff and preparing update.")
447471

config/crd/bases/infrastructure.cluster.x-k8s.io_gcpmanagedcontrolplanes.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ spec:
6666
spec:
6767
description: GCPManagedControlPlaneSpec defines the desired state of GCPManagedControlPlane.
6868
properties:
69+
binaryAuthorization:
70+
description: |-
71+
BinaryAuthorization represents the mode of operation of Binary Authorization for the GKE cluster.
72+
This feature is disabled if this field is not specified.
73+
enum:
74+
- disabled
75+
- project_singleton_policy_enforce
76+
type: string
6977
clusterName:
7078
description: |-
7179
ClusterName allows you to specify the name of the GKE cluster.

config/crd/bases/infrastructure.cluster.x-k8s.io_gcpmanagedcontrolplanetemplates.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ spec:
5353
description: GCPManagedControlPlaneTemplateResourceSpec specifies
5454
an GCP managed control plane template resource.
5555
properties:
56+
binaryAuthorization:
57+
description: |-
58+
BinaryAuthorization represents the mode of operation of Binary Authorization for the GKE cluster.
59+
This feature is disabled if this field is not specified.
60+
enum:
61+
- disabled
62+
- project_singleton_policy_enforce
63+
type: string
5664
clusterNetwork:
5765
description: ClusterNetwork define the cluster network.
5866
properties:

exp/api/v1beta1/gcpmanagedcontrolplane_types.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,18 @@ type AuthenticatorGroupConfig struct {
113113
SecurityGroups string `json:"securityGroups,omitempty"`
114114
}
115115

116+
// BinaryAuthorization is the Binary Authorization evaluation mode of the GKE cluster
117+
// +kubebuilder:validation:Enum=disabled;project_singleton_policy_enforce
118+
type BinaryAuthorization string
119+
120+
const (
121+
// EvaluationModeDisabled disables BinaryAuthorization.
122+
EvaluationModeDisabled BinaryAuthorization = "disabled"
123+
// EvaluationModeProjectSingletonPolicyEnforce enforces Kubernetes admission requests with BinaryAuthorization using the
124+
// project's singleton policy. This is equivalent to setting the
125+
EvaluationModeProjectSingletonPolicyEnforce BinaryAuthorization = "project_singleton_policy_enforce"
126+
)
127+
116128
// ClusterSecurity defines the cluster security options.
117129
type ClusterSecurity struct {
118130
// WorkloadIdentityConfig allows workloads in your GKE clusters to impersonate Identity and Access Management (IAM)

exp/api/v1beta1/types_class.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ type GCPManagedControlPlaneClassSpec struct {
5454
// +optional
5555
ReleaseChannel *ReleaseChannel `json:"releaseChannel,omitempty"`
5656

57+
// BinaryAuthorization represents the mode of operation of Binary Authorization for the GKE cluster.
58+
// This feature is disabled if this field is not specified.
59+
// +optional
60+
BinaryAuthorization *BinaryAuthorization `json:"binaryAuthorization,omitempty"`
61+
5762
// MasterAuthorizedNetworksConfig represents configuration options for master authorized networks feature of the GKE cluster.
5863
// This feature is disabled if this field is not specified.
5964
// +optional

exp/api/v1beta1/zz_generated.deepcopy.go

Lines changed: 5 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)