Skip to content

Commit 357e648

Browse files
committed
Application Credential support
1 parent 0210c18 commit 357e648

File tree

7 files changed

+89
-8
lines changed

7 files changed

+89
-8
lines changed

api/go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,5 @@ replace k8s.io/component-base => k8s.io/component-base v0.31.13 //allow-merging
9393
replace github.com/rabbitmq/cluster-operator/v2 => github.com/openstack-k8s-operators/rabbitmq-cluster-operator/v2 v2.6.1-0.20250929174222-a0d328fa4dec //allow-merging
9494

9595
replace k8s.io/kube-openapi => k8s.io/kube-openapi v0.0.0-20250627150254-e9823e99808e //allow-merging
96+
97+
replace github.com/openstack-k8s-operators/keystone-operator/api => github.com/Deydra71/keystone-operator/api v0.0.0-20251211085602-3e1a3e022c81

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,5 @@ replace k8s.io/component-base => k8s.io/component-base v0.31.13 //allow-merging
142142
replace github.com/rabbitmq/cluster-operator/v2 => github.com/openstack-k8s-operators/rabbitmq-cluster-operator/v2 v2.6.1-0.20250929174222-a0d328fa4dec //allow-merging
143143

144144
replace k8s.io/kube-openapi => k8s.io/kube-openapi v0.0.0-20250627150254-e9823e99808e //allow-merging
145+
146+
replace github.com/openstack-k8s-operators/keystone-operator/api => github.com/Deydra71/keystone-operator/api v0.0.0-20251211085602-3e1a3e022c81

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
github.com/Deydra71/keystone-operator/api v0.0.0-20251211085602-3e1a3e022c81 h1:plax+NFgJJL1SrERyXAnf3jOHRhLTtBlJ2oc7d84EoU=
2+
github.com/Deydra71/keystone-operator/api v0.0.0-20251211085602-3e1a3e022c81/go.mod h1:b98Jl8eyUw8V07l9YiuQnoMlnWC748oV8IhXH15NCC4=
13
github.com/Masterminds/semver/v3 v3.4.0 h1:Zog+i5UMtVoCU8oKka5P7i9q9HgrJeGzI9SA1Xbatp0=
24
github.com/Masterminds/semver/v3 v3.4.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
35
github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI=
@@ -122,8 +124,6 @@ github.com/openstack-k8s-operators/barbican-operator/api v0.6.1-0.20251125115107
122124
github.com/openstack-k8s-operators/barbican-operator/api v0.6.1-0.20251125115107-f489fa5ceb3c/go.mod h1:HURjuNEy1OrE7bn2snCYMzk148bHaD7u7JleEu9h5ws=
123125
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20251205192058-5cfbada0ab96 h1:hPgCcrbRHBPfngaEPe6coaCtcauMolI71lfcLdinrKI=
124126
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20251205192058-5cfbada0ab96/go.mod h1:ZuglN7IqXfIo75WcJwe0NLHhu82Fs3k/5IXptqnO1H4=
125-
github.com/openstack-k8s-operators/keystone-operator/api v0.6.1-0.20251128160419-8b3a77972a77 h1:XzVPjfzxDJwgW8sNGv9K577Ui2mb6Mp3sDItuDmTv9E=
126-
github.com/openstack-k8s-operators/keystone-operator/api v0.6.1-0.20251128160419-8b3a77972a77/go.mod h1:b98Jl8eyUw8V07l9YiuQnoMlnWC748oV8IhXH15NCC4=
127127
github.com/openstack-k8s-operators/lib-common/modules/ansible v0.6.1-0.20251122131503-b76943960b6c h1:RrncYRidCdu8qP6njKRhteaWlY0y6tWhF9qWRhdRdkE=
128128
github.com/openstack-k8s-operators/lib-common/modules/ansible v0.6.1-0.20251122131503-b76943960b6c/go.mod h1:tXxVkkk8HlATwTmDA5RTP3b+c8apfuMM15mZ2wW5iNs=
129129
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20251122131503-b76943960b6c h1:wM8qXCB5mQwSosCvtaydzuXitWVVKBHTzH0A2znQ+Jg=

internal/controller/swift_common.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ import (
2222
"fmt"
2323
"time"
2424

25+
topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
2526
"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
27+
"github.com/openstack-k8s-operators/lib-common/modules/common/env"
2628
"github.com/openstack-k8s-operators/lib-common/modules/common/helper"
2729
"github.com/openstack-k8s-operators/lib-common/modules/common/secret"
28-
"k8s.io/apimachinery/pkg/types"
2930

30-
topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
31-
"github.com/openstack-k8s-operators/lib-common/modules/common/env"
3231
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
32+
"k8s.io/apimachinery/pkg/types"
3333
ctrl "sigs.k8s.io/controller-runtime"
3434
"sigs.k8s.io/controller-runtime/pkg/client"
3535
"sigs.k8s.io/controller-runtime/pkg/log"

internal/controller/swiftproxy_controller.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,20 @@ func (r *SwiftProxyReconciler) Reconcile(ctx context.Context, req ctrl.Request)
578578
return ctrl.Result{}, err
579579
}
580580

581+
// Get Application Credential data if available
582+
useAC := false
583+
acID := ""
584+
acSecret := ""
585+
// Try to get Application Credential for this service (via keystone api helper)
586+
if acData, err := keystonev1.GetApplicationCredentialFromSecret(ctx, r.Client, instance.Namespace, swift.ServiceName); err != nil {
587+
Log.Error(err, "Failed to get ApplicationCredential for service", "service", swift.ServiceName)
588+
} else if acData != nil {
589+
useAC = true
590+
acID = acData.ID
591+
acSecret = acData.Secret
592+
Log.Info("Using ApplicationCredentials auth", "service", swift.ServiceName)
593+
}
594+
581595
// Create a Secret populated with content from templates/
582596
tpl := swiftproxy.SecretTemplates(
583597
instance,
@@ -591,6 +605,9 @@ func (r *SwiftProxyReconciler) Reconcile(ctx context.Context, req ctrl.Request)
591605
os.GetRegion(),
592606
transportURLString,
593607
instance.Spec.APITimeout,
608+
useAC,
609+
acID,
610+
acSecret,
594611
)
595612
err = secret.EnsureSecrets(ctx, helper, instance, tpl, &envVars)
596613
if err != nil {
@@ -846,6 +863,42 @@ func (r *SwiftProxyReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Ma
846863
return nil
847864
}
848865

866+
// Application Credential secret watching function
867+
acSecretFn := func(_ context.Context, o client.Object) []reconcile.Request {
868+
name := o.GetName()
869+
ns := o.GetNamespace()
870+
result := []reconcile.Request{}
871+
872+
// Only handle Secret objects
873+
if _, isSecret := o.(*corev1.Secret); !isSecret {
874+
return nil
875+
}
876+
877+
// Check if this is a swift AC secret by name pattern (ac-swift-secret)
878+
expectedSecretName := keystonev1.GetACSecretName("swift")
879+
if name == expectedSecretName {
880+
// get all SwiftProxy CRs in this namespace
881+
swiftProxies := &swiftv1beta1.SwiftProxyList{}
882+
listOpts := []client.ListOption{
883+
client.InNamespace(ns),
884+
}
885+
if err := r.List(context.Background(), swiftProxies, listOpts...); err != nil {
886+
return nil
887+
}
888+
889+
// Enqueue reconcile for all swift proxy instances
890+
for _, cr := range swiftProxies.Items {
891+
objKey := client.ObjectKey{
892+
Namespace: ns,
893+
Name: cr.Name,
894+
}
895+
result = append(result, reconcile.Request{NamespacedName: objKey})
896+
}
897+
}
898+
899+
return result
900+
}
901+
849902
return ctrl.NewControllerManagedBy(mgr).
850903
For(&swiftv1beta1.SwiftProxy{}).
851904
Owns(&corev1.Secret{}).
@@ -859,6 +912,8 @@ func (r *SwiftProxyReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Ma
859912
handler.EnqueueRequestsFromMapFunc(r.findObjectsForSrc),
860913
builder.WithPredicates(predicate.ResourceVersionChangedPredicate{}),
861914
).
915+
Watches(&corev1.Secret{},
916+
handler.EnqueueRequestsFromMapFunc(acSecretFn)).
862917
Watches(&memcachedv1.Memcached{},
863918
handler.EnqueueRequestsFromMapFunc(memcachedFn)).
864919
Watches(&topologyv1.Topology{},

internal/swiftproxy/templates.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ func SecretTemplates(
4040
keystoneRegion string,
4141
transportURL string,
4242
apiTimeout int,
43+
useApplicationCredentials bool,
44+
applicationCredentialID string,
45+
applicationCredentialSecret string,
4346
) []util.Template {
4447
templateParameters := make(map[string]any)
4548
templateParameters["ServiceUser"] = instance.Spec.ServiceUser
@@ -54,6 +57,13 @@ func SecretTemplates(
5457
templateParameters["TransportURL"] = transportURL
5558
templateParameters["APITimeout"] = apiTimeout
5659

60+
// Application Credential parameters
61+
templateParameters["UseApplicationCredentials"] = useApplicationCredentials
62+
if useApplicationCredentials {
63+
templateParameters["ApplicationCredentialID"] = applicationCredentialID
64+
templateParameters["ApplicationCredentialSecret"] = applicationCredentialSecret
65+
}
66+
5767
// MTLS params
5868
if mc.Status.MTLSCert != "" {
5969
templateParameters["MemcachedAuthCert"] = fmt.Sprint(memcachedv1.CertMountPath())

templates/swiftproxy/config/00-proxy-server.conf

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,18 @@ project_reader_roles = SwiftProjectReader
8080
paste.filter_factory = keystonemiddleware.auth_token:filter_factory
8181
www_authenticate_uri = {{ .KeystonePublicURL }}
8282
auth_url = {{ .KeystonePublicURL }}
83+
{{ if .UseApplicationCredentials -}}
84+
auth_type = v3applicationcredential
85+
application_credential_id = {{ .ApplicationCredentialID }}
86+
application_credential_secret = {{ .ApplicationCredentialSecret }}
87+
{{- else -}}
8388
auth_plugin=password
89+
username = {{ .ServiceUser }}
90+
password = {{ .ServicePassword }}
8491
project_domain_id = default
8592
user_domain_id = default
8693
project_name = service
87-
username = {{ .ServiceUser }}
88-
password = {{ .ServicePassword }}
94+
{{- end }}
8995
delay_auth_decision = True
9096

9197
[filter:s3api]
@@ -108,9 +114,15 @@ use = egg:swift#encryption
108114
[filter:ceilometer]
109115
paste.filter_factory = ceilometermiddleware.swift:filter_factory
110116
auth_url = {{ .KeystonePublicURL }}
117+
{{ if .UseApplicationCredentials -}}
118+
auth_type = v3applicationcredential
119+
application_credential_id = {{ .ApplicationCredentialID }}
120+
application_credential_secret = {{ .ApplicationCredentialSecret }}
121+
{{- else -}}
111122
password = {{ .ServicePassword }}
112123
username = {{ .ServiceUser }}
124+
project_name = service
125+
{{- end }}
113126
region_name = {{ .KeystoneRegion }}
114127
url = {{ .TransportURL }}
115-
project_name = service
116128
nonblocking_notify = True

0 commit comments

Comments
 (0)