Skip to content

Commit 966c5c2

Browse files
xekDeydra71cursoragent
committed
Application Credential support
Co-authored-by: Veronika Fisarova <vfisarov@redhat.com> Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 1dcca25 commit 966c5c2

12 files changed

Lines changed: 249 additions & 12 deletions

api/bases/glance.openstack.org_glanceapis.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ spec:
6565
- single
6666
- edge
6767
type: string
68+
auth:
69+
description: Auth - Parameters related to authentication
70+
properties:
71+
applicationCredentialSecret:
72+
description: ApplicationCredentialSecret - Secret containing Application
73+
Credential ID and Secret
74+
type: string
75+
type: object
6876
containerImage:
6977
description: ContainerImage - GlanceAPI Container Image URL
7078
type: string

api/bases/glance.openstack.org_glances.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,6 +1229,14 @@ spec:
12291229
APITimeout
12301230
minimum: 1
12311231
type: integer
1232+
auth:
1233+
description: Auth - Parameters related to authentication
1234+
properties:
1235+
applicationCredentialSecret:
1236+
description: ApplicationCredentialSecret - Secret containing
1237+
Application Credential ID and Secret
1238+
type: string
1239+
type: object
12321240
customServiceConfig:
12331241
description: |-
12341242
CustomServiceConfig - customize the service config using this parameter to change service defaults,

api/v1beta1/common_types.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ package v1beta1
1919
import (
2020
"strings"
2121

22+
topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
2223
"github.com/openstack-k8s-operators/lib-common/modules/common/service"
2324
"github.com/openstack-k8s-operators/lib-common/modules/common/tls"
2425
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
25-
topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
26-
"k8s.io/apimachinery/pkg/util/validation/field"
2726
corev1 "k8s.io/api/core/v1"
27+
"k8s.io/apimachinery/pkg/util/validation/field"
2828
)
2929

3030
const (
@@ -100,6 +100,11 @@ type GlanceAPITemplate struct {
100100
// TLS - Parameters related to the TLS
101101
TLS tls.API `json:"tls,omitempty"`
102102

103+
// +kubebuilder:validation:Optional
104+
// +operator-sdk:csv:customresourcedefinitions:type=spec
105+
// Auth - Parameters related to authentication
106+
Auth AuthSpec `json:"auth,omitempty"`
107+
103108
// ImageCache - It represents the struct to expose the ImageCache related
104109
// parameters (size of the PVC and cronJob schedule)
105110
// +kubebuilder:validation:Optional
@@ -147,6 +152,14 @@ type APIOverrideSpec struct {
147152
Service map[service.Endpoint]service.RoutedOverrideSpec `json:"service,omitempty"`
148153
}
149154

155+
// AuthSpec defines authentication parameters
156+
type AuthSpec struct {
157+
// +kubebuilder:validation:Optional
158+
// +operator-sdk:csv:customresourcedefinitions:type=spec
159+
// ApplicationCredentialSecret - Secret containing Application Credential ID and Secret
160+
ApplicationCredentialSecret string `json:"applicationCredentialSecret,omitempty"`
161+
}
162+
150163
// SetupDefaults - initializes any CRD field defaults based on environment variables (the defaulting mechanism itself is implemented via webhooks)
151164
func SetupDefaults() {
152165
// Acquire environmental defaults and initialize Glance defaults with them

api/v1beta1/glance_webhook.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"strings"
2222

2323
"github.com/google/go-cmp/cmp"
24+
topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
2425
"github.com/openstack-k8s-operators/lib-common/modules/common/service"
2526
apierrors "k8s.io/apimachinery/pkg/api/errors"
2627
"k8s.io/apimachinery/pkg/runtime"
@@ -29,7 +30,6 @@ import (
2930
logf "sigs.k8s.io/controller-runtime/pkg/log"
3031
"sigs.k8s.io/controller-runtime/pkg/webhook"
3132
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
32-
topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
3333

3434
common_webhook "github.com/openstack-k8s-operators/lib-common/modules/common/webhook"
3535
)
@@ -157,7 +157,6 @@ func (r *GlanceSpecCore) Default() {
157157
}
158158
}
159159

160-
161160
// Check if File is used as a backend for Glance
162161
func isFileBackend(customServiceConfig string, topLevel bool) bool {
163162
availableBackends := GetEnabledBackends(customServiceConfig)

api/v1beta1/glanceapi_webhook.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
20+
"fmt"
21+
22+
"github.com/google/go-cmp/cmp"
23+
apierrors "k8s.io/apimachinery/pkg/api/errors"
2024
"k8s.io/apimachinery/pkg/runtime"
2125
logf "sigs.k8s.io/controller-runtime/pkg/log"
2226
"sigs.k8s.io/controller-runtime/pkg/webhook"
23-
"fmt"
2427
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
25-
"github.com/google/go-cmp/cmp"
26-
apierrors "k8s.io/apimachinery/pkg/api/errors"
2728
)
2829

2930
// GlanceAPIDefaults -

api/v1beta1/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.

config/crd/bases/glance.openstack.org_glanceapis.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ spec:
6565
- single
6666
- edge
6767
type: string
68+
auth:
69+
description: Auth - Parameters related to authentication
70+
properties:
71+
applicationCredentialSecret:
72+
description: ApplicationCredentialSecret - Secret containing Application
73+
Credential ID and Secret
74+
type: string
75+
type: object
6876
containerImage:
6977
description: ContainerImage - GlanceAPI Container Image URL
7078
type: string

config/crd/bases/glance.openstack.org_glances.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,6 +1229,14 @@ spec:
12291229
APITimeout
12301230
minimum: 1
12311231
type: integer
1232+
auth:
1233+
description: Auth - Parameters related to authentication
1234+
properties:
1235+
applicationCredentialSecret:
1236+
description: ApplicationCredentialSecret - Secret containing
1237+
Application Credential ID and Secret
1238+
type: string
1239+
type: object
12321240
customServiceConfig:
12331241
description: |-
12341242
CustomServiceConfig - customize the service config using this parameter to change service defaults,

internal/controller/glance_common.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ import (
4848
// Common static errors for glance controllers
4949
var (
5050
ErrNetworkAttachmentConfig = errors.New("not all pods have interfaces with ips as configured in NetworkAttachments")
51+
ErrACSecretNotFound = errors.New("ApplicationCredential secret not found")
52+
ErrACSecretMissingKeys = errors.New("ApplicationCredential secret missing required keys")
5153
)
5254

5355
// fields to index to reconcile when change
@@ -58,6 +60,7 @@ const (
5860
tlsAPIPublicField = ".spec.tls.api.public.secretName"
5961
topologyField = ".spec.topologyRef.Name"
6062
notificationBusSecretField = ".spec.notificationBusSecret"
63+
authAppCredSecretField = ".spec.auth.applicationCredentialSecret" // #nosec G101
6164
)
6265

6366
var (
@@ -71,6 +74,7 @@ var (
7174
tlsAPIPublicField,
7275
topologyField,
7376
notificationBusSecretField,
77+
authAppCredSecretField,
7478
}
7579
)
7680

internal/controller/glanceapi_controller.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,18 @@ func (r *GlanceAPIReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Man
286286
return err
287287
}
288288

289+
// index authAppCredSecretField
290+
if err := mgr.GetFieldIndexer().IndexField(context.Background(), &glancev1.GlanceAPI{}, authAppCredSecretField, func(rawObj client.Object) []string {
291+
// Extract the application credential secret name from the spec, if one is provided
292+
cr := rawObj.(*glancev1.GlanceAPI)
293+
if cr.Spec.Auth.ApplicationCredentialSecret == "" {
294+
return nil
295+
}
296+
return []string{cr.Spec.Auth.ApplicationCredentialSecret}
297+
}); err != nil {
298+
return err
299+
}
300+
289301
// Watch for changes to any CustomServiceConfigSecrets. Global secrets
290302
svcSecretFn := func(_ context.Context, o client.Object) []reconcile.Request {
291303
var namespace = o.GetNamespace()
@@ -1285,6 +1297,28 @@ func (r *GlanceAPIReconciler) generateServiceConfig(
12851297
"Wsgi": wsgi,
12861298
}
12871299

1300+
// Try to get Application Credential from the secret specified in the CR
1301+
if instance.Spec.Auth.ApplicationCredentialSecret != "" {
1302+
acSecretObj, _, err := secret.GetSecret(ctx, h, instance.Spec.Auth.ApplicationCredentialSecret, instance.Namespace)
1303+
if err != nil {
1304+
if k8s_errors.IsNotFound(err) {
1305+
Log.Info("ApplicationCredential secret not found, waiting", "secret", instance.Spec.Auth.ApplicationCredentialSecret)
1306+
return fmt.Errorf("%w: %s", ErrACSecretNotFound, instance.Spec.Auth.ApplicationCredentialSecret)
1307+
}
1308+
Log.Error(err, "Failed to get ApplicationCredential secret", "secret", instance.Spec.Auth.ApplicationCredentialSecret)
1309+
return err
1310+
}
1311+
acID, okID := acSecretObj.Data[keystonev1.ACIDSecretKey]
1312+
acSecretData, okSecret := acSecretObj.Data[keystonev1.ACSecretSecretKey]
1313+
if okID && len(acID) > 0 && okSecret && len(acSecretData) > 0 {
1314+
templateParameters["ApplicationCredentialID"] = string(acID)
1315+
templateParameters["ApplicationCredentialSecret"] = string(acSecretData)
1316+
Log.Info("Using ApplicationCredentials auth", "secret", instance.Spec.Auth.ApplicationCredentialSecret)
1317+
} else {
1318+
return fmt.Errorf("%w: %s", ErrACSecretMissingKeys, instance.Spec.Auth.ApplicationCredentialSecret)
1319+
}
1320+
}
1321+
12881322
// (OSPRH-18291)Only set EndpointID parameter when the Endpoint has been
12891323
// created and the associated ID is set in the keystoneapi CR. Because we
12901324
// have the Keystone CR, we get the Region parameter mirrored in its

0 commit comments

Comments
 (0)