Skip to content

Commit

Permalink
salt, storage-operator: Limit allowed Salt states
Browse files Browse the repository at this point in the history
Reduce to only state formulas in `metalk8s.volumes`.

Fixes: #1528
  • Loading branch information
gdemonet committed Jun 19, 2020
1 parent 846d96b commit 547a96b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
4 changes: 3 additions & 1 deletion salt/metalk8s/salt/master/files/master-99-metalk8s.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ external_auth:
storage-operator:
- '*':
- 'disk.dump'
- 'state.sls'
- 'state.sls':
kwargs:
mods: 'metalk8s\.volumes.*'
- '@jobs'

# `kubeconfig` file and `context` used by salt to interact with apiserver
Expand Down
3 changes: 2 additions & 1 deletion tests/post/features/salt_api.feature
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ Feature: SaltAPI
Scenario: Login to SaltAPI using a ServiceAccount
Given the Kubernetes API is available
When we login to SaltAPI with the ServiceAccount 'storage-operator'
Then we can invoke '["disk.dump", "state.sls"]' on '*'
Then we can invoke '["disk.dump", {"state.sls": {"kwargs": {"mods": r"metalk8s\.volumes.*"}}]' on '*'
And we have '@jobs' perms
And we can not ping all minions
And we can not run state 'test.nop' on '*'

Scenario: Login to SaltAPI using an incorrect password
Given the Kubernetes API is available
Expand Down
15 changes: 15 additions & 0 deletions tests/post/steps/test_salt_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,21 @@ def ping_all_minions(host, context, negated):
assert result_data['return'][0] != []


@then(parsers.parse(
"we can{negated:Negation} run state '{module}' on '{targets}'",
extra_types={'Negation': _negation}
))
def run_state_on_targets(host, context, negated, module, targets):
result = _salt_call(context, 'state.sls', tgt=targets,
kwarg={'mods': module})

if negated:
assert result.status_code == 401
assert 'No permission' in result.text
else:
assert result.status_code == 200


@then('authentication fails')
def authentication_fails(host, context):
assert context['salt-api']['login-status-code'] == 401
Expand Down

0 comments on commit 547a96b

Please sign in to comment.