Skip to content

Commit d342380

Browse files
committed
Ignore mount path for git-credentials secrets and mount as file
Ignore any mount-path annotations on secrets labelled 'controller.devfile.io/git-credential'. Instead, always mount the merged git credentials secret to `/.git-credentials`. Additionally, mount the credentials file as files rather than using subpath mounts, in order to ensure changes to the on-cluster secret can be propagated to the running workspace without requiring a restart. Signed-off-by: Angel Misevski <[email protected]>
1 parent 26bf462 commit d342380

File tree

2 files changed

+4
-31
lines changed

2 files changed

+4
-31
lines changed

pkg/provision/automount/gitconfig.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import (
2424
k8sclient "sigs.k8s.io/controller-runtime/pkg/client"
2525
)
2626

27+
const mergedGitCredentialsMountPath = "/.git-credentials/"
28+
2729
// ProvisionGitConfiguration takes care of mounting git credentials and a gitconfig into a devworkspace.
2830
func ProvisionGitConfiguration(api sync.ClusterAPI, namespace string) (*Resources, error) {
2931
credentialsSecrets, tlsConfigMaps, err := getGitResources(api, namespace)
@@ -45,12 +47,7 @@ func ProvisionGitConfiguration(api sync.ClusterAPI, namespace string) (*Resource
4547
return nil, &AutoMountError{IsFatal: true, Err: err}
4648
}
4749

48-
credentialsMountPath, err := getCredentialsMountPath(credentialsSecrets)
49-
if err != nil {
50-
return nil, &AutoMountError{IsFatal: true, Err: err}
51-
}
52-
53-
gitConfigMap, err := constructGitConfig(namespace, credentialsMountPath, tlsConfigMaps, baseGitConfig)
50+
gitConfigMap, err := constructGitConfig(namespace, mergedGitCredentialsMountPath, tlsConfigMaps, baseGitConfig)
5451
if err != nil {
5552
return nil, &AutoMountError{IsFatal: true, Err: err}
5653
}
@@ -79,7 +76,7 @@ func ProvisionGitConfiguration(api sync.ClusterAPI, namespace string) (*Resource
7976
return nil, &AutoMountError{IsFatal: false, Err: err}
8077
}
8178
resources := flattenAutomountResources([]Resources{
82-
getAutomountSecret(credentialsMountPath, constants.DevWorkspaceMountAsSubpath, mergedCredentialsSecret),
79+
getAutomountSecret(mergedGitCredentialsMountPath, constants.DevWorkspaceMountAsFile, mergedCredentialsSecret),
8380
getAutomountConfigmap("/etc/", constants.DevWorkspaceMountAsSubpath, gitConfigMap),
8481
})
8582

pkg/provision/automount/templates.go

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -125,27 +125,3 @@ func mergeGitCredentials(namespace string, credentialSecrets []corev1.Secret) (*
125125
}
126126
return mergedCredentials, nil
127127
}
128-
129-
// getCredentialsMountPath returns the mount path to be used by all git credentials secrets. If no secrets define a mountPath,
130-
// the root path ('/credentials') is used. If secrets define conflicting mountPaths, an error is returned and represents an invalid
131-
// configuration. If any secret defines a mountPath, that mountPath overrides the mountPath for all secrets that do not
132-
// define a mountPath. If there are no credentials secrets, the empty string is returned
133-
func getCredentialsMountPath(secrets []corev1.Secret) (string, error) {
134-
if len(secrets) == 0 {
135-
return "", nil
136-
}
137-
mountPath := ""
138-
for _, secret := range secrets {
139-
secretMountPath := secret.Annotations[constants.DevWorkspaceMountPathAnnotation]
140-
if secretMountPath != "" {
141-
if mountPath != "" && secretMountPath != mountPath {
142-
return "", fmt.Errorf("auto-mounted git credentials have conflicting mountPaths: %s, %s", mountPath, secretMountPath)
143-
}
144-
mountPath = secretMountPath
145-
}
146-
}
147-
if mountPath == "" {
148-
mountPath = "/"
149-
}
150-
return mountPath, nil
151-
}

0 commit comments

Comments
 (0)