Managing Configuration Drift and Auditing with Salt
Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE dmacvicar@suse.com
Managing Configuration Drift and Auditing with Salt Duncan - - PowerPoint PPT Presentation
Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE dmacvicar@suse.com How to manage infrastructure? 2 Sysadmin Alexis Manages his servers with bash #!/bin/bash scripts.
Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE dmacvicar@suse.com
2
#!/bin/bash cat <<EOF | server1 server2 EOF while read line ssh -q user1@${line} zypper up done
scripts.
process.
➔Writes "Configuration
Management" recipes and templates
➔They reside in `git`.
/etc/motd: file.managed:
apache: pkg.installed
5
Mode 2 Mode 1
Agile, DevOps Waterfall, ITIL New & Uncertain Projects Conventional Projects Short Cycle (days, weeks) Long-cycle Times (months) Agility Reliability
“If somebody changes the configuration, I just re-apply it and the tool brings it to the correct state.”
7
Configuration management (CM) is a systems engineering process for establishing and maintaining consistency of a product's performance, functional, and physical attributes with its requirements, design, and operational information throughout its life.
➢Has become a pragmatic way to implement configuration
management for IT infrastructure.
➢We know how to manage change of source code. ➢We have the tools and processes for it.
Ports: 4505-4506 Master Minion Minion Minion ØMQ
configuration commands results master minions
$ salt ‘*’ pkg.install foo $ salt host1 docker.pause c001 $ salt ‘web*’ cmd.run \ ‘cat /etc/fstab’ $ salt ‘*’ state.apply
configuration commands results master minions
/etc/motd: file.managed:
apache: pkg.installed
$ salt minion1 state.apply test=True
minion1:
Function: file.managed Result: None Comment: The file /etc/motd is set to be changed Started: 10:06:05.021643 Duration: 30.339 ms Changes:
@@ -1 +1 @@
+This is my managed motd Summary for minion1
Failed: 0
$ useradd -r mudserver
$ salt minion1 state.apply test=True
minion1:
Function: file.managed Result: None Comment: The file /etc/motd is set to be changed Started: 10:06:05.021643 Duration: 30.339 ms Changes:
@@ -1 +1 @@
+This is my managed motd Summary for minion1
Failed: 0
It was not part of the configuration. # We can express... joe: user.present # How to express? any other: user.absent
➔snapper is to snapshots what
zypper/apt-get/dnf are to packages.
➔First demoed in SUSECon 2011! ➔Main feature of SUSE Linux
Enterprise 12
(don't forget to mention btrfs)
snapper list-configs snapper list snapper create snapper mount <number> snapper status <number1>..<number2> snapper diff <number1>..<number2> [files] snapper undochange <number1>..<number2> [files]
YaST and zypper take snapshots automatically In grub menu you can boot old snapshots
configuration commands results master minions
salt '*' snapper.list_snapshots salt '*' snapper.get_snapshot salt '*' snapper.create_snapshot salt '*' snapper.undo salt '*' snapper.diff
$ salt minion2 snapper.run function=file.append args='["/etc/motd", "some text"]' minion2: Wrote 1 lines to "/etc/motd" ... pre | 21 | | Thu.. | root | number | salt job 6668 | salt_jid=6668 post | 22 | 21 | Thu... | root | number | salt job 6668 | salt_jid=6668
$ salt minion2 snapper.diff_jid 6668 minion2:
+++ /.snapshots/22/snapshot/etc/motd @@ -1 +1,2 @@ Have a lot of fun... +some text
snapper.undo_jid also works
Back to the baseline problem, imagine you could say:
# Starting from snapshot #3 baseline:
# then ... /etc/motd: file.managed:
apache: pkg.installed
States Templates
You can!
my_baseline: snapper.baseline_snapshot:
/etc/motd: file.managed:
States Templates
If the somebody adds a new user, a drift against the baseline rule will happen:
$ salt minion1 state.apply test=True minion1:
Function: snapper.baseline_snapshot Result: None Comment: 1 files changes are set to be undone ... Changes: ... /etc/passwd: ... diff:
+++ /.snapshots/21/snapshot/etc/passwd @@ -22,5 +22,3 @@ duncan:x:1000:100:Duncan Mac-Vicar P.:/home/duncan:/bin/zsh
... Succeeded: 2 (unchanged=2, changed=2)
If you apply the state (eg. no `test=True`), the system will be set to the state of the baseline snapshot before applying the rest of the states.
$ salt minion1 state.apply
Current
Baseline state
... states
$ salt '*' snapper.create_baseline
Creates a snapshot and adds a “baseline” tag to the “userdata” property of each snapshot.
Type # Pre Date Desc userdata single current ... post 20 19 Sept 26... important=no ... single 22 Sept 26... baseline_tag=baseline
without affecting your state.
used.
last_production: snapper.baseline_snapshot:
C
f i g u r e D r i f t D
u m e n t B a s e l i n e Audit
package
https://docs.saltstack.com/en/develop/topics/releases/carbon.html
$ salt minion2 snapper.run function=state.apply
Survey groups the returned values in pools of unique results.
salt-run survey.diff survey_sort=up "*" cmd.run 'cat /etc/hosts' This tells you which server differs from the others.
v1
/etc/hosts
v2
/etc/hosts
salt 'web*' pkg.diff /etc/sudoers Tells the difference between the `/etc/sudoers` of the original package vs the installed one.
Tool Purpose Nova Auditing Framework Pulsar File integrity monitor, security events Nebula Query infrastructure security snapshots Quasar Reporting
44
Mode 2 Mode 1
Agile, DevOps Waterfall, ITIL New & Uncertain Projects Conventional Projects Short Cycle (days, weeks) Long-cycle Times (months) Agility Reliability
45
Deployment High Availability Scaling Monitoring Networking
Softwar e Defined *: Comput e Storage Network Magnum Containers Mode 1 Mode 2
46
47
salt://happy
container image...
48
FROM ubuntu:12.04 RUN zypper -n in foo RUN echo "key=val" > /etc/foo/config
49
foo: pkg.installed /etc/foo/config: file.managed:
salt://myapp/foo.config salt mybuilder0 dockerng.state myapp mods=myapp
50
Reuse states and templates across workloads. Access templates, pillar data (eg. secrets) directly from Salt. Access to Salt modules for configuration. Implemented as ability to run arbitrary Salt modules inside running
containers.
Auditing
51
53