Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion actions/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ replace (
require (
github.com/qase-tms/qase-go/qase-api-client v1.2.1
github.com/rancher/rancher/pkg/apis v0.0.0
github.com/rancher/shepherd v0.0.0-20260226203127-be7fc5d07fbe
github.com/rancher/shepherd v0.0.0-20260331204545-07fe2049a102
github.com/rancher/tfp-automation v0.0.0-20260223200320-56541017be04
)

Expand Down
4 changes: 2 additions & 2 deletions actions/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ github.com/rancher/rancher/pkg/apis v0.0.0-20260105201356-c4811cb9f2af h1:ZXIKdK
github.com/rancher/rancher/pkg/apis v0.0.0-20260105201356-c4811cb9f2af/go.mod h1:NwWL+lOkxPRibQ6j+9uFSo6t1CJ18z1oY4OYJMOQ/R0=
github.com/rancher/rke v1.8.0 h1:87jeoOccnnNCq27YgWgMh4o0GVrrVKbw+zfo+cHMZlo=
github.com/rancher/rke v1.8.0/go.mod h1:x9N1abruzDFMwTpqq2cnaDYpKCptlNoW8VraNWB6Pc4=
github.com/rancher/shepherd v0.0.0-20260226203127-be7fc5d07fbe h1:pnjTBrkZ3Dk3EcCSfhFDYztr3Vf3qXUHaT80L3WlPVY=
github.com/rancher/shepherd v0.0.0-20260226203127-be7fc5d07fbe/go.mod h1:SJtW8Jqv0rphZzsGnvB965YdyR2FqFtB+TbbzVLt8F4=
github.com/rancher/shepherd v0.0.0-20260331204545-07fe2049a102 h1:hkDHfP7JNlvE9b1J3gEjJnRZu5xo5lnwdBp3ofB1Nlc=
github.com/rancher/shepherd v0.0.0-20260331204545-07fe2049a102/go.mod h1:SJtW8Jqv0rphZzsGnvB965YdyR2FqFtB+TbbzVLt8F4=
github.com/rancher/system-upgrade-controller/pkg/apis v0.0.0-20250930163923-f2c9e60b1078 h1:1MJSgYkgXhr/Zc5idJkKa10SiBQd0HVtbxVOBoghlzY=
github.com/rancher/system-upgrade-controller/pkg/apis v0.0.0-20250930163923-f2c9e60b1078/go.mod h1:CV2Soy/Skw8/SA9dDJVgpeHxoEdtjYkNpNy6xvvC5kA=
github.com/rancher/tfp-automation v0.0.0-20260223200320-56541017be04 h1:pvs3UWfAtSK+7Wf+/unqV/sALE8Tr3kuOeu9QVDq+G4=
Expand Down
164 changes: 164 additions & 0 deletions actions/scim/scim.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
package scim

import (
"context"
"crypto/rand"
"encoding/hex"
"fmt"

"github.com/rancher/shepherd/clients/rancher"
scimclient "github.com/rancher/shepherd/clients/rancher/auth/scim"
"github.com/rancher/shepherd/extensions/defaults"
"github.com/rancher/shepherd/pkg/clientbase"
"github.com/rancher/tests/actions/auth"
"github.com/rancher/tests/actions/features"
"github.com/sirupsen/logrus"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
kwait "k8s.io/apimachinery/pkg/util/wait"
)

const (
SCIMFeatureFlag = "scim"
SCIMSecretNamespace = "cattle-global-data"
SCIMSecretDataKey = "token"

scimSecretKindLabel = "cattle.io/kind"
scimSecretKindValue = "scim-auth-token"
scimAuthProviderLabel = "authn.management.cattle.io/provider"
)

var errNoSCIMTokenSecret = fmt.Errorf("no SCIM token secret found")

// FetchSCIMBearerToken retrieves the SCIM bearer token for the given auth provider from the cattle-global-data namespace
func FetchSCIMBearerToken(client *rancher.Client, providerName string) (string, error) {
logrus.Infof("Fetching SCIM bearer token from %s by label %s=%s",
SCIMSecretNamespace, scimAuthProviderLabel, providerName)
selector := labels.SelectorFromSet(labels.Set{
scimSecretKindLabel: scimSecretKindValue,
scimAuthProviderLabel: providerName,
})
list, err := client.WranglerContext.Core.Secret().List(
SCIMSecretNamespace,
metav1.ListOptions{LabelSelector: selector.String()},
)
if err != nil {
return "", err
}
if len(list.Items) == 0 {
return "", errNoSCIMTokenSecret
}
newest := &list.Items[0]
for i := 1; i < len(list.Items); i++ {
if list.Items[i].CreationTimestamp.After(newest.CreationTimestamp.Time) {
newest = &list.Items[i]
}
}
if len(list.Items) > 1 {
logrus.Warnf("Multiple SCIM token secrets found for provider %s, using newest: %s", providerName, newest.Name)
}
token, ok := newest.Data[SCIMSecretDataKey]
if !ok || len(token) == 0 {
return "", fmt.Errorf("key %q not found or empty in secret %s/%s",
SCIMSecretDataKey, SCIMSecretNamespace, newest.Name)
}
logrus.Infof("Found SCIM token in secret %s/%s", SCIMSecretNamespace, newest.Name)
return string(token), nil
}

// CreateSCIMTokenSecret generates a new random bearer token and stores it as a Kubernetes secret in the cattle-global-data namespace
func CreateSCIMTokenSecret(client *rancher.Client, providerName string) (string, error) {
b := make([]byte, 32)
if _, err := rand.Read(b); err != nil {
return "", err
}
token := hex.EncodeToString(b)

secretName := fmt.Sprintf("scim-token-%s", providerName)
secret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: secretName,
Namespace: SCIMSecretNamespace,
Labels: map[string]string{
scimSecretKindLabel: scimSecretKindValue,
scimAuthProviderLabel: providerName,
},
},
Data: map[string][]byte{
SCIMSecretDataKey: []byte(token),
},
}

logrus.Infof("Creating SCIM token secret %s/%s", SCIMSecretNamespace, secretName)
_, err := client.WranglerContext.Core.Secret().Create(secret)
if err != nil {
return "", err
}
return token, nil
}

// SetupSCIMClient ensures the SCIM feature flag is enabled and the auth provider
// is active, then fetches or creates a bearer token secret and returns a configured
// SCIM client ready to make requests against the given provider.
func SetupSCIMClient(client *rancher.Client, providerName string) (*scimclient.Client, error) {
enabled, err := features.IsEnabled(client, SCIMFeatureFlag)
if err != nil {
return nil, err
}

if !enabled {
if err = features.UpdateFeatureFlag(client, SCIMFeatureFlag, true); err != nil {
return nil, err
}
}

if err = auth.EnsureAuthProviderEnabled(client, providerName); err != nil {
return nil, err
}

token, err := FetchSCIMBearerToken(client, providerName)
if err != nil {
if err != errNoSCIMTokenSecret {
return nil, err
}
logrus.Infof("No SCIM token secret found for provider %s, creating one", providerName)
token, err = CreateSCIMTokenSecret(client, providerName)
if err != nil {
return nil, err
}
}

return scimclient.NewClient(&clientbase.ClientOpts{
URL: fmt.Sprintf("https://%s", client.RancherConfig.Host),
TokenKey: token,
Insecure: true,
}, providerName), nil
}

// NewSCIMClientWithToken returns a SCIM client configured with the given host, provider, and bearer token
func NewSCIMClientWithToken(host, providerName, token string) *scimclient.Client {
return scimclient.NewClient(&clientbase.ClientOpts{
URL: fmt.Sprintf("https://%s", host),
TokenKey: token,
Insecure: true,
}, providerName)
}


// WaitForSCIMResourceDeletion polls a SCIM GET endpoint until it returns 404.
func WaitForSCIMResourceDeletion(getFunc func() (int, error)) error {
return kwait.PollUntilContextTimeout(
context.Background(),
defaults.FiveSecondTimeout,
defaults.OneMinuteTimeout,
false,
func(ctx context.Context) (bool, error) {
status, err := getFunc()
if err != nil {
return false, err
}
return status == 404, nil
},
)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ require (
github.com/qase-tms/qase-go/pkg/qase-go v1.0.7
github.com/qase-tms/qase-go/qase-api-client v1.2.1
github.com/rancher/rancher v0.0.0-20251223145833-24cecce3325e
github.com/rancher/shepherd v0.0.0-20260226203127-be7fc5d07fbe
github.com/rancher/shepherd v0.0.0-20260331204545-07fe2049a102
github.com/rancher/tests/actions v0.0.0-20260206233613-bf28ed655999
github.com/rancher/tests/interoperability v0.0.0-00010101000000-000000000000
github.com/rancher/tfp-automation v0.0.0-20260223200320-56541017be04
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2188,8 +2188,8 @@ github.com/rancher/rancher/pkg/apis v0.0.0-20260105201356-c4811cb9f2af h1:ZXIKdK
github.com/rancher/rancher/pkg/apis v0.0.0-20260105201356-c4811cb9f2af/go.mod h1:NwWL+lOkxPRibQ6j+9uFSo6t1CJ18z1oY4OYJMOQ/R0=
github.com/rancher/rke v1.8.0 h1:87jeoOccnnNCq27YgWgMh4o0GVrrVKbw+zfo+cHMZlo=
github.com/rancher/rke v1.8.0/go.mod h1:x9N1abruzDFMwTpqq2cnaDYpKCptlNoW8VraNWB6Pc4=
github.com/rancher/shepherd v0.0.0-20260226203127-be7fc5d07fbe h1:pnjTBrkZ3Dk3EcCSfhFDYztr3Vf3qXUHaT80L3WlPVY=
github.com/rancher/shepherd v0.0.0-20260226203127-be7fc5d07fbe/go.mod h1:SJtW8Jqv0rphZzsGnvB965YdyR2FqFtB+TbbzVLt8F4=
github.com/rancher/shepherd v0.0.0-20260331204545-07fe2049a102 h1:hkDHfP7JNlvE9b1J3gEjJnRZu5xo5lnwdBp3ofB1Nlc=
github.com/rancher/shepherd v0.0.0-20260331204545-07fe2049a102/go.mod h1:SJtW8Jqv0rphZzsGnvB965YdyR2FqFtB+TbbzVLt8F4=
github.com/rancher/system-upgrade-controller/pkg/apis v0.0.0-20250930163923-f2c9e60b1078 h1:1MJSgYkgXhr/Zc5idJkKa10SiBQd0HVtbxVOBoghlzY=
github.com/rancher/system-upgrade-controller/pkg/apis v0.0.0-20250930163923-f2c9e60b1078/go.mod h1:CV2Soy/Skw8/SA9dDJVgpeHxoEdtjYkNpNy6xvvC5kA=
github.com/rancher/tfp-automation v0.0.0-20260223200320-56541017be04 h1:pvs3UWfAtSK+7Wf+/unqV/sALE8Tr3kuOeu9QVDq+G4=
Expand Down
2 changes: 1 addition & 1 deletion interoperability/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ require (
github.com/rancher/fleet/pkg/apis v0.15.0-alpha.4
github.com/rancher/norman v0.8.1
github.com/rancher/rancher/pkg/apis v0.0.0
github.com/rancher/shepherd v0.0.0-20260226203127-be7fc5d07fbe
github.com/rancher/shepherd v0.0.0-20260331204545-07fe2049a102
github.com/rancher/tests/actions v0.0.0-20260206233613-bf28ed655999
github.com/rancher/tfp-automation v0.0.0-20260223200320-56541017be04
github.com/sirupsen/logrus v1.9.3
Expand Down
4 changes: 2 additions & 2 deletions interoperability/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2081,8 +2081,8 @@ github.com/rancher/rancher/pkg/apis v0.0.0-20260105201356-c4811cb9f2af h1:ZXIKdK
github.com/rancher/rancher/pkg/apis v0.0.0-20260105201356-c4811cb9f2af/go.mod h1:NwWL+lOkxPRibQ6j+9uFSo6t1CJ18z1oY4OYJMOQ/R0=
github.com/rancher/rke v1.8.0 h1:87jeoOccnnNCq27YgWgMh4o0GVrrVKbw+zfo+cHMZlo=
github.com/rancher/rke v1.8.0/go.mod h1:x9N1abruzDFMwTpqq2cnaDYpKCptlNoW8VraNWB6Pc4=
github.com/rancher/shepherd v0.0.0-20260226203127-be7fc5d07fbe h1:pnjTBrkZ3Dk3EcCSfhFDYztr3Vf3qXUHaT80L3WlPVY=
github.com/rancher/shepherd v0.0.0-20260226203127-be7fc5d07fbe/go.mod h1:SJtW8Jqv0rphZzsGnvB965YdyR2FqFtB+TbbzVLt8F4=
github.com/rancher/shepherd v0.0.0-20260331204545-07fe2049a102 h1:hkDHfP7JNlvE9b1J3gEjJnRZu5xo5lnwdBp3ofB1Nlc=
github.com/rancher/shepherd v0.0.0-20260331204545-07fe2049a102/go.mod h1:SJtW8Jqv0rphZzsGnvB965YdyR2FqFtB+TbbzVLt8F4=
github.com/rancher/system-upgrade-controller/pkg/apis v0.0.0-20250930163923-f2c9e60b1078 h1:1MJSgYkgXhr/Zc5idJkKa10SiBQd0HVtbxVOBoghlzY=
github.com/rancher/system-upgrade-controller/pkg/apis v0.0.0-20250930163923-f2c9e60b1078/go.mod h1:CV2Soy/Skw8/SA9dDJVgpeHxoEdtjYkNpNy6xvvC5kA=
github.com/rancher/tfp-automation v0.0.0-20260223200320-56541017be04 h1:pvs3UWfAtSK+7Wf+/unqV/sALE8Tr3kuOeu9QVDq+G4=
Expand Down
44 changes: 44 additions & 0 deletions validation/auth/scim/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# SCIM Test Suite

This package contains Golang automation tests for Rancher's SCIM 2.0 integration.

## Pre-requisites

- Ensure you have an existing cluster that the user has access to. If you do not have a downstream cluster in Rancher, create one first before running this test.
- Ensure OpenLDAP is configured in your Rancher instance. For full OpenLDAP configuration details see the [OpenLDAP auth provider README](../provider/openldap/README.md).

## Test Setup

Your GO suite should be set to `-run ^Test<TestSuite>$`

- To run the scim_openldap_test.go, set the GO suite to `-run ^TestSCIMOpenLDAPSuite$`

In your config file, set the following:

```yaml
rancher:
host: "rancher_server_address"
adminToken: "rancher_admin_token"
insecure: true
clusterName: "downstream_cluster_name"

openLDAP:
hostname: "open_ldap_host"
serviceAccount:
distinguishedName: "cn=admin,dc=qa,dc=example,dc=com"
password: "<service_account_password>"
users:
searchBase: "ou=users,dc=qa,dc=example,dc=com"
admin:
username: "<admin_username>"
password: "<admin_password>"
groups:
searchBase: "ou=groups,dc=qa,dc=example,dc=com"

openLdapAuthInput:
users:
- username: "<username1>"
password: "<password1>"
- username: "<username2>"
password: "<password2>"
```
Loading
Loading