Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible automation for 4.1.5 #2

Open
rx294 opened this issue Dec 29, 2021 · 1 comment · May be fixed by #6
Open

Possible automation for 4.1.5 #2

rx294 opened this issue Dec 29, 2021 · 1 comment · May be fixed by #6
Labels
enhancement New feature or request

Comments

@rx294
Copy link

rx294 commented Dec 29, 2021

describe 'Manual control' do

Possible automation

items =json(command:"kubectl get rolebinding,clusterrolebinding --all-namespaces -o json").params['items']

control "test" do
items.each do |i|
  next if i['subjects'].nil?
  describe "service accounts for clusterrolebinding:#{i['roleRef']['name']}" do
    subject {i['subjects'].map{|x| x['name']}}
    it { should_not include 'default'}
  end
end
end


items =json(command:"kubectl get serviceaccount -A -o json").params['items']

control "test" do
items.each do |i|
  next unless i['metadata']['name'].eql?('default')
  describe "Default service account in namespace:#{i['metadata']['namespace']}" do
    subject {i}
    its(['automountServiceAccountToken']) { should cmp 'false'}
  end
end
end


Please consider if the above model is a cleaner implementation for ur check in 4.1.6 ... although ur current version works fine ...the above might make for better reporting.

@wdower
Copy link
Collaborator

wdower commented Jan 2, 2022

This makes sense, but the first block should be restricted to only check actual service account rolebinding objects:

  bindings = json(command:"kubectl get rolebinding,clusterrolebinding --all-namespaces -o json").params['items']

  bindings.each do |binding|

    subjects = binding['subjects']
    next if subjects.nil?
    sa = subjects.find { |x| x['kind'] == 'ServiceAccount'}
    next if sa.nil?

    describe "Service account for clusterrolebinding: #{binding['roleRef']['name']}" do
      subject { sa['name'] }
      it { should_not eq 'default' }
    end
  end

It still has to check a ton of objects, but fewer than if you don't filter down to only service account rolebindings.

The second block I'm fine with; I will leave 4.1.6's logic alone for now.

@wdower wdower linked a pull request Jan 2, 2022 that will close this issue
@Amndeep7 Amndeep7 added the enhancement New feature or request label Feb 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants