@@ -877,6 +877,131 @@ func TestPullSecretAuth(t *testing.T) {
877877 Should (poolAllUpdated (1 , digest ))
878878}
879879
880+ // TestPullSecretRotation verifies that the daemon picks up rotated
881+ // registry credentials. It creates a pool targeting the auth registry,
882+ // waits for the initial upgrade, then rotates the auth registry's
883+ // credentials via bink, updates the K8s Secret to match, and triggers
884+ // a second upgrade. The second upgrade succeeding proves the daemon
885+ // re-reads the secret and authenticates with the new credentials.
886+ //
887+ // Not parallel: this test modifies the shared auth registry.
888+ func TestPullSecretRotation (t * testing.T ) {
889+ e2eutil .Providers (t , "bink" )
890+ g := NewWithT (t )
891+ g .SetDefaultEventuallyTimeout (pollTimeout )
892+ g .SetDefaultEventuallyPollingInterval (pollInterval )
893+
894+ env := e2eutil .New (t )
895+ if env .RegistryUser () == "" || env .RegistryPassword () == "" {
896+ t .Skip ("E2E_REGISTRY_USER / E2E_REGISTRY_PASSWORD not set" )
897+ }
898+
899+ ctx := context .Background ()
900+ nodeName := env .AddNode (t )
901+
902+ registryHost := env .RegistryHost ()
903+ authUpdateRef := env .AuthImageRef ()
904+ authUpdate2Ref := registryHost + "/node@" + env .NodeImageUpdate2Digest ()
905+
906+ // Phase 1: Create pull secret and pool targeting the auth update
907+ // image. The daemon must pull through the authenticated registry.
908+ authStr := base64 .StdEncoding .EncodeToString (
909+ []byte (env .RegistryUser () + ":" + env .RegistryPassword ()),
910+ )
911+ dockerCfg := fmt .Sprintf (
912+ `{"auths":{%q:{"auth":"%s"}}}` ,
913+ registryHost , authStr ,
914+ )
915+ secret := & corev1.Secret {
916+ ObjectMeta : metav1.ObjectMeta {
917+ Name : env .TestID () + "-pull-secret" ,
918+ Namespace : testutil .OperatorNamespaceName ,
919+ },
920+ Type : corev1 .SecretTypeDockerConfigJson ,
921+ Data : map [string ][]byte {
922+ corev1 .DockerConfigJsonKey : []byte (dockerCfg ),
923+ },
924+ }
925+ g .Expect (env .Client .Create (ctx , secret )).To (Succeed ())
926+ t .Cleanup (func () { _ = env .Client .Delete (ctx , secret ) })
927+
928+ pool := env .NewPool ("pull-rotate" , authUpdateRef ,
929+ testutil .WithPullSecret (secret .Name , secret .Namespace ),
930+ )
931+ g .Expect (env .Client .Create (ctx , pool )).To (Succeed ())
932+
933+ testutil .WaitForNodeIdle (t , g , ctx , env .Client , nodeName , 8 * time .Minute ,
934+ HaveField ("Booted" , HaveField ("Image" , Equal (authUpdateRef ))),
935+ )
936+
937+ t .Logf ("Node %q reached Idle with auth update image" , nodeName )
938+
939+ g .Eventually (fetchPoolStatus (ctx , env .Client , pool )).
940+ Should (poolAllUpdated (1 , env .NodeImageUpdateDigest ()))
941+
942+ // Phase 2: Rotate the auth registry credentials via bink and
943+ // update the K8s Secret to match.
944+ rotatedUser := "rotated"
945+ rotatedPass := "rotated-pass"
946+
947+ t .Cleanup (func () {
948+ cmd := exec .Command ("bink" , "registry" , "update-credentials" ,
949+ "--registry-user" , env .RegistryUser (),
950+ "--registry-password" , env .RegistryPassword (),
951+ )
952+ cmd .Stdout = os .Stdout
953+ cmd .Stderr = os .Stderr
954+ if err := cmd .Run (); err != nil {
955+ t .Logf ("WARNING: restoring auth registry credentials: %v" , err )
956+ }
957+ })
958+
959+ rotateCmd := exec .Command ("bink" , "registry" , "update-credentials" ,
960+ "--registry-user" , rotatedUser ,
961+ "--registry-password" , rotatedPass ,
962+ )
963+ rotateCmd .Stdout = os .Stdout
964+ rotateCmd .Stderr = os .Stderr
965+ g .Expect (rotateCmd .Run ()).To (Succeed (), "rotating auth registry credentials" )
966+
967+ t .Logf ("Rotated auth registry to user=%s" , rotatedUser )
968+
969+ var current corev1.Secret
970+ g .Expect (env .Client .Get (ctx , client .ObjectKeyFromObject (secret ), & current )).To (Succeed ())
971+
972+ rotatedAuthStr := base64 .StdEncoding .EncodeToString (
973+ []byte (rotatedUser + ":" + rotatedPass ),
974+ )
975+ rotatedCfg := fmt .Sprintf (
976+ `{"auths":{%q:{"auth":"%s"}}}` ,
977+ registryHost , rotatedAuthStr ,
978+ )
979+ current .Data [corev1 .DockerConfigJsonKey ] = []byte (rotatedCfg )
980+ g .Expect (env .Client .Update (ctx , & current )).To (Succeed ())
981+
982+ t .Logf ("Updated pull secret %q with rotated credentials" , secret .Name )
983+
984+ // Phase 3: Patch pool to a different auth image to trigger an
985+ // upgrade that exercises the rotated credentials.
986+ modified := pool .DeepCopy ()
987+ modified .Spec .Image .Ref = authUpdate2Ref
988+ g .Expect (env .Client .Patch (ctx , modified , client .MergeFrom (pool ))).To (Succeed ())
989+ * pool = * modified
990+
991+ t .Logf ("Patched pool to auth update2 image %s" , authUpdate2Ref )
992+
993+ // Phase 4: The upgrade completing proves the daemon re-read the
994+ // rotated secret and authenticated with the new registry credentials.
995+ testutil .WaitForNodeIdle (t , g , ctx , env .Client , nodeName , 8 * time .Minute ,
996+ HaveField ("Booted" , HaveField ("Image" , Equal (authUpdate2Ref ))),
997+ )
998+
999+ t .Logf ("Node %q upgraded with rotated credentials" , nodeName )
1000+
1001+ g .Eventually (fetchPoolStatus (ctx , env .Client , pool )).
1002+ Should (poolAllUpdated (1 , env .NodeImageUpdate2Digest ()))
1003+ }
1004+
8801005// TestControllerRecovery provisions a worker node, starts a rollout, and
8811006// scales the controller deployment to zero while that rollout is actively in
8821007// progress (the node is staging and cannot reboot until the controller drains
0 commit comments