Configuration Management
Traditional Configuration Management (CM)
Pressman: “is a set of tracking and control activities that are initiated when a software engineering projects begins and terminates when software is taken out of operation”.
Configuration management originates from the 1950s, when spacecraft failures resulted from undocumented changes.
Example configuration management plans
On the failure of traditional CM.
Traditional configuration management focused on preventing unregulated and undocumented change.
A worthy goal… however
In reality, a burdensome and incomplete process can be just as problematic as no process at all.
Reality: 200 page documents filled with out-of-date instructions and overly strict processes.
Toward Modern CM practices.
In short, a continuous deployment pipeline and associated development practices can help regulate and ensure quality changes to software better than a static word document.
Still, one more ingredient missing...
Recall, code alone is not enough.
We also need CM for Computing Environments!
Configuration + Code
Simple Example: When Time Breaks
Real-world occurrence: Mockito build fails:
Cause: Differences in timezone file structure, which is changed in Ubuntu 16.04, and breaks how timezones are implemented in JDK 7.
Why are bash scripts not enough?
Recall some of the basic issues you’ve faced running commands in bash scripts for HW0 and HW1...
Modern CM Components
git, branches
package managers, task and build managers
Inventory, configuration scripts.
Infrastructure update patterns
Orchestration and configuration tools
Testing and compliance
How important are dependencies?
Dependencies are common cause for build failures.
A Quantitative Study of Java Software Buildability
Why dependency management is difficult for programmers?
[Horton and Parnin 2018] ICSME’18
There are over 300k Python snippets, but limited api.
As a result, we scrapped the web UI.
10,259 public Python gists, with at least one star.
Gistable =
Gist + Executable
Can gists be executed?
Not really.
Can code be executed?
Only 25% of Python code snippets from Stack Overflow are runnable [Wang MSR’16]
We replicated result on Python Notebooks [Rule 2018 CHI].
Only 8% are executable.
Can the solution be easy?
Just pip install the list of packages!
Packages = [‘dashtable’];
Naive solution
Can the solution be easy?
Not quite.
ImportError: No
module named bs4.
We asked developers to create Dockerfiles for 240 failing gists.
Developers reported spending 20 minutes to 2 hours to create a Dockerfile.
For 33% of gists, developers could not create a successful Dockerfile.
We identified first root cause for failure based on successful Dockerfile
Package Managers
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.25.0</version>
</dependency>�</dependencies>
Platform package managers
Install system dependencies and binaries.
Examples: choco (Windows), brew (Mac), apt-get, yum (Linux).
Library package managers
Install software dependencies.
Examples: npm, nuget, bower, maven, pip, rubygems.
Maven’s pom.xml
Tip: Use pinned versions on dependencies.
Why are Package Managers not enough?
Infrastructure Inventory
What are all the assets you own?
[dbservers]
152.14.XX.XX
[workers]
45.55.XX.XX
45.55.XX.XX
104.236.XX.XX
45.55.XX.XX
104.131.XX.XX
45.55.XX.XX
138.197.XX.XX
104.236.XX.XX
45.55.XX.XX
104.131.XX.XX
Configuration is Code (infrastructure as code)
Any change to an asset should be checked in.
Challenges
Configuration Tools
Ansible - “Playbook” scripts run over ssh
---
# The playbook creates a new database test and populates data in the database to test the sharding.
- hosts: $servername
user: root
tasks:
- name: Create a new database and user
mongodb_user: login_user=admin login_password=${mongo_admin_pass} login_port=${mongos_port} database=test user=admin password=${mongo_admin_pass} state=present
- name: Pause for the user to get created and replicated
pause: minutes=3
- name: Execute the collection creation script
command: /usr/bin/mongo localhost:${mongos_port}/test -u admin -p ${mongo_admin_pass} /tmp/testsharding.js
- name: Enable sharding on the database and collection
command: /usr/bin/mongo localhost:${mongos_port}/admin -u admin -p ${mongo_admin_pass} /tmp/enablesharding.js
Configuration Tools
Puppet - Less hands on, agents run on server.
puppet module install thias-mongodb
mongodb::key { '/etc/mongodb.key':� content => 'c9otjehasAvlactocPiphAgC9',�}�class { '::mongodb':� bind_ip => '0.0.0.0',� auth => 'true',� rest => 'true',� replset => 'rs0',� keyfile => '/etc/mongodb.key',� verbose => 'true',�}
Configuration Tools
Chef - “Cookbooks” ruby-based task and build recipes
mongodb_user { testuser:� username => 'testuser',� ensure => present,� password_hash => mongodb_password('testuser', 'p@ssw0rd'),� database => testdb,� roles => ['readWrite', 'dbAdmin'],� tries => 10,� require => Class['mongodb::server'],�}
Other useful configuration tools.
Post-configuration help with cloud-init:
Provisioning help with Terraform:
Provision cluster on VSphere.
Configuration Models
Configuration Server
ASSET
agent
ASSET
agent
ASSET
agent
config tool
PULL
Configuration Server
ASSET
ASSET
ASSET
config tool
PUSH
Idempotency
Definition 1: Applying the same operation, multiple times results in the same state.
Definition 2: A system is able to reach a desired state, regardless of its current state.
Example
ssh-keyscan -H >> ~/.ssh/known_hosts
NOT IDEMPOTENT
---�# ansible playbook that adds ssh fingerprints to known_hosts�- hosts: all� connection: local� gather_facts: no� tasks:� - command: /usr/bin/ssh-keyscan -H {{ ansible_host }}� register: keyscan� - lineinfile: name=~/.ssh/known_hosts create=yes line={{ item }}� with_items: '{{ keyscan.stdout_lines }}'
IDEMPOTENT*
Exercise + Discussion
Explain idempotency to your a partner.
What are some examples of idempotent and non-idempotent operations?
Infrastructure update patterns
Living infrastructure: Maintain same dedicated instance.
Immutable infrastructure: Deploy new read-only instance.
Configuration change
apply
Configuration change
construct
replace
Other Analogies
Pets vs. Cattle
Snowflake vs. Phoenix servers.
Living Infrastructure
How
Implications
Immutable Infrastructure
How
Implications
Patterns for Building Images
Online snapshot
Examples: Packer
Rootfs construction
Examples: Linuxkit, Slim
Building Images
Living infrastructure vs. immutable infrastructure
Activity
Explain the concepts to a partner.
Discuss the potential benefits and drawbacks of each approach.
Share insights with the class.
Environment verification and testing.
Reachability: Environment can access other internal and external resources and services.
Availability: Environment provides expected service.
Capability: Environment supports required operations.
Identifiable: Environment contains required items.
Insecure Configuration Patterns (ICPs)
Admin by default Use of Insecure HTTP
Empty password Use of weak cryptography algorithms
Hard-coded secret Unrestricted ip address
In summary
Identify: all system and package dependencies using package managers. All infrastructure components with inventory and variables in configuration scripts. Secrets in vaults. All software components built with reproducible builds.
Manage: Make changes to computing environments with configuration tools.
Variations: Tag infrastructure instances, allow configuration change to be directed to subpopulation.
Quality: Linters, testing-in-production, automatic rollbacks.
Traceability: Track all infrastructure code is checked and tracked along with normal codes.
One possible configuration management plan for computing environments
CM Principles (by Michael DeHaan)
Some research...
Automatic inference and repair of computing environments.
Automatic analysis and transformation of computing environments.
DockerizeMe: Automatic inference of Dockerfile
Given a code snippet, can we infer associated set of dependencies?
[Horton and Parnin, ICSE 2019]
General approach: Reason over a large set of uncertain and incomplete offline database.
We automatically build wheels, extract all resources provided for top 10k packages.
Core Python Contributor asked:
Dynamically extract dependencies.
biopython package => Bio, BioSQL modules
Build association rules from Dockerfiles, Pipfiles, requirements.txt
Detecting when code breaks.
What about an “everything 🥯 bagel” docker image?
10 GB “behemoth” image.
“everything 🥯 bagel” images can be problematic.
Just one more package, please?
Enormous security attack surface.
Maintenance nightmare.
Put docker image on a diet.
Can reduce Dockerfile to run given code snippet.
Still, each build of Dockerfile can be very slow! Needs specialized optimization.
Program synthesis
Automatically generate ansible task given a bash command?
Automatic mapping between commands and ansible modules
Image synthesis