Skip to content
Merged
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
29 changes: 29 additions & 0 deletions manager/controlapi/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,21 @@ func validateConfigRefsSpec(spec api.TaskSpec) error {
return nil
}

// check if we're using a config as a CredentialSpec -- if so, we need to
// verify
var (
credSpecConfig string
credSpecConfigFound bool
)
if p := container.Privileges; p != nil {
if cs := p.CredentialSpec; cs != nil {
// if there is no config in the credspec, then this will just be
// assigned to emptystring anyway, so we don't need to check
// existence.
credSpecConfig = cs.GetConfig()
}
}

// Keep a map to track all the targets that will be exposed
// The string returned is only used for logging. It could as well be struct{}{}
existingTargets := make(map[string]string)
Expand Down Expand Up @@ -421,6 +436,20 @@ func validateConfigRefsSpec(spec api.TaskSpec) error {

existingTargets[fileName] = configRef.ConfigName
}

if configRef.GetRuntime() != nil {
if configRef.ConfigID == credSpecConfig {
credSpecConfigFound = true
}
}
}

if credSpecConfig != "" && !credSpecConfigFound {
return status.Errorf(
codes.InvalidArgument,
"CredentialSpec references config '%s', but that config isn't in config references with RuntimeTarget",
credSpecConfig,
)
}

return nil
Expand Down
15 changes: 15 additions & 0 deletions manager/controlapi/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,21 @@ func TestConfigValidation(t *testing.T) {
)
assert.NoError(t, err)

// test CredentialSpec without ConfigReference
serviceSpec = createSpec("missingruntimetarget", "imagemissingruntimetarget", 1)
serviceSpec.Task.GetContainer().Privileges = &api.Privileges{
CredentialSpec: &api.Privileges_CredentialSpec{
Source: &api.Privileges_CredentialSpec_Config{
Config: configRefCredSpec.ConfigID,
},
},
}
_, err = ts.Client.CreateService(
context.Background(), &api.CreateServiceRequest{Spec: serviceSpec},
)
t.Logf("error when missing configreference: %v", err)
assert.Error(t, err)

// test config target conflicts on update
serviceSpec1 := createServiceSpecWithConfigs("service5", configRef2, configRef3)
// Copy this service, but delete the configs for creation
Expand Down