IAM-backed ObjectStores generate wildcard Secret RBAC
Summary
When an ObjectStore uses AWS IAM role inheritance (inheritFromIAMRole: true) and does not reference any credential Secrets, the generated <cluster>-barman-cloud Role still contains a secrets rule with no resourceNames.
In Kubernetes RBAC, an omitted or empty resourceNames list does not restrict the rule to no objects; it allows the verbs on all resources of that type. As a result, an IAM-backed barman-cloud instance can get/list/watch every Secret in the namespace even though barman-cloud does not need any Secret for the AWS credential chain.
Why this matters
Deployments using IRSA, pod identity, or IMDS typically set inheritFromIAMRole: true so barman-cloud gets credentials from the pod environment. In that mode, barman-cloud returns before reading AWS credential Secret references, so the plugin should not grant Secret access unless a credential Secret is actually needed.
Expected behavior
If no credential Secret names are collected for the ObjectStores referenced by a cluster, the generated Role should not include a secrets rule. For AWS credentials with inheritFromIAMRole: true, AWS Secret references should be ignored the same way Azure default/managed identity credentials are ignored today.
Actual behavior
The Role includes a secrets rule with an empty resourceNames field, which grants access to all Secrets in the namespace.
Proposed fix
- Skip AWS credential Secret references when
inheritFromIAMRoleis true. - Omit the generated
secretsPolicyRule when the collected Secret name set is empty. - Keep the existing scoped
secretsrule when explicit credential Secret refs are present.
Hi @martinohansen! I'm Dosu and I’m helping the plugin-barman-cloud team.
I confirmed the issue you've described. The root cause is in CollectSecretNamesFromCredentials in internal/cnpgi/operator/specs/secrets.go [1] — the AWS credential branch unconditionally appends secret references without checking inheritFromIAMRole:
if barmanCredentials.AWS != nil {
references = append(
references,
barmanCredentials.AWS.AccessKeyIDReference,
barmanCredentials.AWS.SecretAccessKeyReference,
barmanCredentials.AWS.RegionReference,
barmanCredentials.AWS.SessionToken,
)
}
In contrast, Azure already has the exact pattern you'd want here [2]:
if barmanCredentials.Azure != nil {
if !barmanCredentials.Azure.UseDefaultAzureCredentials &&
!barmanCredentials.Azure.InheritFromAzureAD {
references = append(references, ...)
}
}
Additionally, BuildRoleRules in internal/cnpgi/operator/rbac/role.go always emits the secrets PolicyRule regardless of whether the collected set is empty [3]. The stringset.ToSortedList() returns an empty non-nil slice []string{} [4], which in Kubernetes RBAC means "all secrets in the namespace" — exactly the wildcard behavior you've identified.
A fix would need two changes:
-
Skip AWS secret references when
inheritFromIAMRoleis true — guard the AWS branch similarly to Azure:if barmanCredentials.AWS != nil && !barmanCredentials.AWS.InheritFromIAMRole { references = append(references, ...) } -
Omit the secrets PolicyRule when no secrets are needed — in
BuildRoleRules, only append the secrets rule ifsecretsSetis non-empty:if secretsSet.Len() > 0 { rules = append(rules, rbacv1.PolicyRule{...}) }
There are existing tests for the Azure skip logic [5] that could serve as a template for equivalent AWS inheritFromIAMRole tests.
To reply, just mention @dosu.
Docs are dead. Just use Dosu.
We hit this in v0.14.0 while running the plugin operator with least-privilege RBAC. It has a second concrete failure mode in addition to the wildcard access itself: Kubernetes rejects creation of the generated Role under RBAC privilege-escalation prevention because the plugin operator does not already hold the emitted secrets get/list/watch permissions.
The reconciliation error is shaped like:
roles.rbac.authorization.k8s.io "<cluster>-barman-cloud" is forbidden:
user "system:serviceaccount:<namespace>:barman-cloud-plugin" is attempting
to grant RBAC permissions not currently held:
{APIGroups:[""], Resources:["secrets"], Verbs:["get" "watch" "list"]}
So deployments currently see one of two outcomes:
- The upstream broad operator permissions allow Role creation, and the database ServiceAccount receives access to every Secret in its namespace.
- A constrained operator correctly lacks general Secret access, and the pre-reconcile hook loops on this anti-escalation error.
Our temporary workaround is to reference an intentionally non-sensitive region Secret from the ObjectStore and grant the operator access to that exact Secret name. That makes the generated Role's resourceNames non-empty without granting escalate or general Secret access.
Omitting the Secret PolicyRule when the collected set is empty remains the clean fix; it removes both the access issue and the anti-escalation failure.
Thanks for this fix — we hit #892 on EKS with Pod Identity: with inheritFromIAMRole: true, the generated <cluster>-barman-cloud Role grants read access to every Secret in the namespace. Like the workaround described in the issue thread, we currently reference a non-sensitive Secret in the ObjectStore so the rule gets scoped.
The approach looks right to us. A few notes:
- The Secret names are now collected through
SecretNames()in the barman-cloud library, so theinheritFromIAMRolefiltering would probably live there now, alongside the existing Azure handling. - With IAM inheritance, the SSE-C key Secret is still read, so it should stay in the list.
- Never emitting a
secretsrule with an emptyresourceNamesis the key safety net, whatever the credential mode. It would also fix the RBAC escalation error reported in the issue for least-privilege operator setups. - A test covering the upgrade of an existing Role (wildcard rule removed on reconcile) would be nice.
If you don't have the bandwidth, I'm happy to take this over and open updated PRs (crediting your work, of course). Just let me know!