-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Application, Role, Group, RoleAssignment support
- Loading branch information
1 parent
1c07021
commit e109a80
Showing
24 changed files
with
2,841 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
Copyright 2021 The Crossplane Authors. | ||
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 rbac contains Azure rbac API versions | ||
package rbac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
Copyright 2019 The Crossplane Authors. | ||
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 v1alpha1 contains managed resources for Azure rbac. | ||
// +kubebuilder:object:generate=true | ||
// +groupName=rbac.azure.crossplane.io | ||
// +versionName=v1alpha1 | ||
package v1alpha1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/* | ||
Copyright 2019 The Crossplane Authors. | ||
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 v1alpha1 | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/pkg/errors" | ||
|
||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
"github.com/crossplane/crossplane-runtime/pkg/reference" | ||
"github.com/crossplane/crossplane-runtime/pkg/resource" | ||
) | ||
|
||
// RoleID - reference to id of role | ||
func RoleID() reference.ExtractValueFn { | ||
return func(mg resource.Managed) string { | ||
s, ok := mg.(*Role) | ||
if !ok { | ||
return "" | ||
} | ||
return s.Spec.RoleID | ||
} | ||
} | ||
|
||
// ADGroupID - reference to id of ad group | ||
func ADGroupID() reference.ExtractValueFn { | ||
return func(mg resource.Managed) string { | ||
s, ok := mg.(*ADGroup) | ||
if !ok { | ||
return "" | ||
} | ||
return s.Spec.GroupID | ||
} | ||
} | ||
|
||
// ResolveReferences of this ServicePrincipal | ||
func (mg *ServicePrincipal) ResolveReferences(ctx context.Context, c client.Reader) error { | ||
r := reference.NewAPIResolver(c, mg) | ||
|
||
// Resolve spec.applicationID | ||
rsp, err := r.Resolve(ctx, reference.ResolutionRequest{ | ||
CurrentValue: mg.Spec.ApplicationID, | ||
Reference: mg.Spec.ApplicationIDRef, | ||
Selector: mg.Spec.ApplicationIDSelector, | ||
To: reference.To{Managed: &Application{}, List: &ApplicationList{}}, | ||
Extract: reference.ExternalName(), | ||
}) | ||
if err != nil { | ||
return errors.Wrap(err, "spec.applicationID") | ||
} | ||
mg.Spec.ApplicationID = rsp.ResolvedValue | ||
mg.Spec.ApplicationIDRef = rsp.ResolvedReference | ||
|
||
return nil | ||
} | ||
|
||
// ResolveReferences of this ServicePrincipal | ||
func (mg *RoleAssignment) ResolveReferences(ctx context.Context, c client.Reader) error { | ||
r := reference.NewAPIResolver(c, mg) | ||
|
||
switch mg.Spec.PrincipalType { | ||
case "": | ||
fallthrough | ||
case "service-principal": | ||
// Resolve spec.principalID | ||
rsp, err := r.Resolve(ctx, reference.ResolutionRequest{ | ||
CurrentValue: mg.Spec.PrincipalID, | ||
Reference: mg.Spec.GroupIDRef, | ||
Selector: mg.Spec.GroupIDSelector, | ||
To: reference.To{Managed: &ServicePrincipal{}, List: &ServicePrincipalList{}}, | ||
Extract: reference.ExternalName(), | ||
}) | ||
if err != nil { | ||
return errors.Wrap(err, "spec.principalID") | ||
} | ||
mg.Spec.PrincipalID = rsp.ResolvedValue | ||
mg.Spec.PrincipalIDRef = rsp.ResolvedReference | ||
case "group": | ||
// Resolve spec.principalID | ||
rsp, err := r.Resolve(ctx, reference.ResolutionRequest{ | ||
CurrentValue: mg.Spec.PrincipalID, | ||
Reference: mg.Spec.GroupIDRef, | ||
Selector: mg.Spec.GroupIDSelector, | ||
To: reference.To{Managed: &ADGroup{}, List: &ADGroupList{}}, | ||
Extract: ADGroupID(), | ||
}) | ||
if err != nil { | ||
return errors.Wrap(err, "spec.principalID") | ||
} | ||
mg.Spec.PrincipalID = rsp.ResolvedValue | ||
mg.Spec.GroupIDRef = rsp.ResolvedReference | ||
default: | ||
return errors.New("invalid spec.principalType should be one of: ['group', 'service-principal']") | ||
} | ||
|
||
// Resolve spec.roleID | ||
rsp, err := r.Resolve(ctx, reference.ResolutionRequest{ | ||
CurrentValue: mg.Spec.RoleID, | ||
Reference: mg.Spec.RoleIDRef, | ||
Selector: mg.Spec.RoleIDSelector, | ||
To: reference.To{Managed: &Role{}, List: &RoleList{}}, | ||
Extract: RoleID(), | ||
}) | ||
if err != nil { | ||
return errors.Wrap(err, "spec.roleID") | ||
} | ||
mg.Spec.RoleID = rsp.ResolvedValue | ||
mg.Spec.RoleIDRef = rsp.ResolvedReference | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
Copyright 2019 The Crossplane Authors. | ||
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 v1alpha1 | ||
|
||
import ( | ||
"reflect" | ||
|
||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"sigs.k8s.io/controller-runtime/pkg/scheme" | ||
) | ||
|
||
// Package type metadata. | ||
const ( | ||
Group = "rbac.azure.crossplane.io" | ||
Version = "v1alpha1" | ||
) | ||
|
||
var ( | ||
// SchemeGroupVersion is group version used to register these objects | ||
SchemeGroupVersion = schema.GroupVersion{Group: Group, Version: Version} | ||
|
||
// SchemeBuilder is used to add go types to the GroupVersionKind scheme | ||
SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion} | ||
) | ||
|
||
// Application type metadata. | ||
var ( | ||
ApplicationKind = reflect.TypeOf(Application{}).Name() | ||
ApplicationGroupKind = schema.GroupKind{Group: Group, Kind: ApplicationKind}.String() | ||
ApplicationKindAPIVersion = ApplicationKind + "." + SchemeGroupVersion.String() | ||
ApplicationGroupVersionKind = SchemeGroupVersion.WithKind(ApplicationKind) | ||
|
||
ServicePrincipalKind = reflect.TypeOf(ServicePrincipal{}).Name() | ||
ServicePrincipalGroupKind = schema.GroupKind{Group: Group, Kind: ServicePrincipalKind}.String() | ||
ServicePrincipalKindAPIVersion = ServicePrincipalKind + "." + SchemeGroupVersion.String() | ||
ServicePrincipalGroupVersionKind = SchemeGroupVersion.WithKind(ServicePrincipalKind) | ||
|
||
RoleAssignmentKind = reflect.TypeOf(RoleAssignment{}).Name() | ||
RoleAssignmentGroupKind = schema.GroupKind{Group: Group, Kind: RoleAssignmentKind}.String() | ||
RoleAssignmentKindAPIVersion = RoleAssignmentKind + "." + SchemeGroupVersion.String() | ||
RoleAssignmentGroupVersionKind = SchemeGroupVersion.WithKind(RoleAssignmentKind) | ||
|
||
RoleKind = reflect.TypeOf(Role{}).Name() | ||
RoleGroupKind = schema.GroupKind{Group: Group, Kind: RoleKind}.String() | ||
RoleKindAPIVersion = RoleKind + "." + SchemeGroupVersion.String() | ||
RoleGroupVersionKind = SchemeGroupVersion.WithKind(RoleKind) | ||
|
||
ADGroupKind = reflect.TypeOf(ADGroup{}).Name() | ||
ADGroupGroupKind = schema.GroupKind{Group: Group, Kind: ADGroupKind}.String() | ||
ADGroupKindAPIVersion = ADGroupKind + "." + SchemeGroupVersion.String() | ||
ADGroupGroupVersionKind = SchemeGroupVersion.WithKind(ADGroupKind) | ||
) | ||
|
||
func init() { | ||
SchemeBuilder.Register(&Application{}, &ApplicationList{}) | ||
SchemeBuilder.Register(&ServicePrincipal{}, &ServicePrincipalList{}) | ||
SchemeBuilder.Register(&RoleAssignment{}, &RoleAssignmentList{}) | ||
SchemeBuilder.Register(&Role{}, &RoleList{}) | ||
SchemeBuilder.Register(&ADGroup{}, &ADGroupList{}) | ||
} |
Oops, something went wrong.