53
Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE [email protected]

Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

  • Upload
    dinhdat

  • View
    231

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

Managing Configuration Drift and Auditing with Salt

Duncan Mac-Vicar P.

Director, Data Center Management R&D, SUSE

[email protected]

Page 2: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

2

How to manage infrastructure?

Page 3: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

#!/bin/bashcat <<EOF |server1server2EOFwhile read line ssh -q user1@${line} zypper updone

Sysadmin Alexis

●Manages his servers with bash scripts.●They reside in`~/bin`●Strict ownership and approval process.

Page 4: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

New colleague: Devops Adrian

➔Writes "Configuration Management" recipes and templates➔They reside in `git`.

/etc/motd: file.managed: - source: salt://common/motd

apache: pkg.installed

Page 5: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

5

The two brains of IT

Mode 2Mode 1

Agile, DevOpsWaterfall, ITIL

New & Uncertain ProjectsConventional Projects

Short Cycle (days, weeks)Long-cycle Times (months)

AgilityReliability

Page 6: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

Devops Adrian explains

“If somebody changes the configuration, I just re-apply it and the tool brings it to the correct state.”

Page 7: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

7

Sysadmin Alexis reads:

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.

Page 8: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

Infrastructure as code

➢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.

Page 9: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

Salt 101

Ports: 4505-4506

Master

Minion

Minion

Minion

ØMQ

Page 10: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

Salt 101

configuration commands

results

master

minions

$ salt ‘*’ pkg.install foo

$ salt host1 docker.pause c001

$ salt ‘web*’ cmd.run \

‘cat /etc/fstab’

$ salt ‘*’ state.apply

Page 11: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

What is a state?

configuration commands

results

master

minions

/etc/motd:

file.managed:

- source: salt://common/motd

apache:

pkg.installed

Page 12: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

“state” is how Salt calls configuration, in its declarative form.

States

Page 13: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

Non-Compliant system

$ salt minion1 state.apply test=True

minion1:---------- ID: /etc/motd 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: ---------- diff: --- +++ @@ -1 +1 @@ -Have a lot of fun... +This is my managed motd

Summary for minion1------------Succeeded: 1 (unchanged=1, changed=1)Failed: 0------------Total states run: 1

Page 14: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

New trainee

$ useradd -r mudserver

Page 15: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

Let’s run it again

$ salt minion1 state.apply test=True

minion1:---------- ID: /etc/motd 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: ---------- diff: --- +++ @@ -1 +1 @@ -Have a lot of fun... +This is my managed motd

Summary for minion1------------Succeeded: 1 (unchanged=1, changed=1)Failed: 0------------Total states run: 1

Page 16: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

The change was not detected

It was not part of the configuration.

# We can express...

joe:

user.present

# How to express?

any other:

user.absent

Page 17: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

●Devops tools focus in creating new systems.●Not all change accounted. “Is it really Configuration Management”.● What they call "Configuration Management" is really "Automation".●The novelty is more about the declarative approach (vs imperative).

Disappointed Sysadmin

Page 18: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

Are “Classic” IT priorities the same?

●Detecting Configuration Drift.●Auditing Compliance.●Documenting infrastructure. Drift

Audit

Document

Page 19: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

“Incomplete” Configuration

Baseline

States Templates

Page 20: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

Where is the baseline?

In configuration management, a "baseline" is an agreed description of the attributes of a

product, at a point in time, which serves as a basis for defining change. ~~MIL-HDBK-61

Page 21: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

How to define a baseline?How to integrate it with the rest of the

configuration?

Page 22: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

Snapper (http://snapper.io)

➔snapper is to snapshots what zypper/apt-get/dnf are to packages.➔First demoed in SUSECon 2011!➔Main feature of SUSE Linux Enterprise 12

Page 23: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

Created by SUSE, available everywhere

●https://wiki.archlinux.org/index.php/Snapper●https://apps.fedoraproject.org/packages/snapper●https://packages.debian.org/search?keywords=snapper

(don't forget to mention btrfs)

Page 24: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

Snapper 101

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 automaticallyIn grub menu you can boot old snapshots

Page 25: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

YaST2 snapper

Page 26: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

Salt and Snapper integration I

configuration commands

results

master

minions

salt '*' snapper.list_snapshots

salt '*' snapper.get_snapshot

salt '*' snapper.create_snapshot

salt '*' snapper.undo

salt '*' snapper.diff

Page 27: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE
Page 28: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

Salt andSnapper Integration

$ 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

Page 29: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

Salt and Snapper integration

$ salt minion2 snapper.diff_jid 6668

minion2:

----------

/etc/motd:

--- /.snapshots/21/snapshot/etc/motd

+++ /.snapshots/22/snapshot/etc/motd

@@ -1 +1,2 @@

Have a lot of fun...

+some text

snapper.undo_jid also works

Page 30: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

State module

Back to the baseline problem, imagine you could say:

# Starting from snapshot #3baseline: - ????# then ...

/etc/motd: file.managed: - source: salt://common/motd

apache: pkg.installed

Baseline

States Templates

Page 31: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

State module

You can!

my_baseline:

snapper.baseline_snapshot:

- number: 20

- ignore:

- /var/log

- /var/cache

/etc/motd:

file.managed:

- source: salt://common/motd

Baseline

States Templates

Page 32: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

If the somebody adds a new user, a drift against the baseline rule will happen:

$ salt minion1 state.apply test=Trueminion1:---------- ID: my_baseline Function: snapper.baseline_snapshot Result: None Comment: 1 files changes are set to be undone ... Changes: ... /etc/passwd: ... diff: --- /etc/passwd +++ /.snapshots/21/snapshot/etc/passwd @@ -22,5 +22,3 @@ duncan:x:1000:100:Duncan Mac-Vicar P.:/home/duncan:/bin/zsh -mudserver:x:167:100::/home/mudserver:/bin/bash---------- ID: /etc/motd...Succeeded: 2 (unchanged=2, changed=2)

Page 33: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

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.

Applying states

$ salt minion1 state.apply

Current

Baseline state

... states

Page 34: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

Managing snapshots by number?

$ 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 0 current

...

post 20 19 Sept 26... important=no

...

single 22 Sept 26... baseline_tag=baseline

Page 35: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

Baseline tags

●You can move the baseline, without affecting your state.●The last tagged snapshot will be used.

last_production: snapper.baseline_snapshot: - tag: baseline

ConfigureD

riftDocum

ent

Bas

eline

Audit

Page 36: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

Salt Snapper module

●Already submitted upstream. Will be part of Carbon release.●Also available in SUSE Linux Enterprise/SUSE Manager 2015.8.x Salt package●Carbon also supports automatic snapshots when applying states

https://docs.saltstack.com/en/develop/topics/releases/carbon.html

Page 37: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

(about state snapshots)

$ salt minion2 snapper.run function=state.apply

Page 38: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

Other Resources to Manage Drift

Page 39: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

Salt Survey Runner Module

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

Page 40: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

Salt Package Module

salt 'web*' pkg.diff /etc/sudoers

Tells the difference between the `/etc/sudoers` of the original package vs the installed one.

Page 41: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

Hubble (http://hubblestack.io)

Tool Purpose

Nova Auditing Framework

Pulsar File integrity monitor, security events

Nebula Query infrastructure security snapshots

Quasar Reporting

Page 42: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

Available Nova modules

● grep (configuration values)● iptables (firewall rules)● netstat (listening ports)● openscap (CVE scan)● openssl (cert validation & expiration)● pkg (installed packages)● service (running services)● stat (ownerships & permissions)● sysctl (kernel parameters)● vulners.com (CVE scan)

Page 43: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

Future work

Page 44: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

44

The two brains of IT

Mode 2Mode 1

Agile, DevOpsWaterfall, ITIL

New & Uncertain ProjectsConventional Projects

Short Cycle (days, weeks)Long-cycle Times (months)

AgilityReliability

Page 45: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

45

“Bimodal Datacenter”

DeploymentHigh

AvailabilityScaling MonitoringNetworking

Software Defined *:ComputeStorageNetwork

Magnum

Containers

Mode 1 Mode 2

Page 46: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

46

Docker images

Page 47: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

47

●You bought into the hype and automated everything with Salt.

● You have Salt states and templates for all your infrastructure. salt://happy

● Now you wand to deploy an app into a container and you need a container image...

Motivation

Page 48: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

48

Dockerfiles

FROM ubuntu:12.04

RUN zypper -n in foo

RUN echo "key=val" > /etc/foo/config

Page 49: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

49

Building images

foo:

pkg.installed

/etc/foo/config:

file.managed:

- source: salt://myapp/foo.config

salt mybuilder0 dockerng.state myapp mods=myapp

Page 50: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

50

Benefits

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

Page 51: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

51

Thanks for listening

Page 52: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE
Page 53: Managing Configuration Drift and Auditing with Salt - SUSE€¦ · Managing Configuration Drift and Auditing with Salt Duncan Mac-Vicar P. Director, Data Center Management R&D, SUSE

53