bbinet / salt-formula-linux

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Linux Fomula

Linux Operating Systems:

  • Ubuntu
  • CentOS
  • RedHat
  • Fedora
  • Arch

Sample Pillars

Linux System

Basic Linux box

Linux with system users, some with password set:

Warning

If no password variable is passed, any predifined password will be removed.

Configure password expiration parameters

The following login.defs parameters can be overridden per-user:

  • PASS_MAX_DAYS
  • PASS_MIN_DAYS
  • PASS_WARN_DAYS
  • INACTIVE

Configure sudo for users and groups under /etc/sudoers.d/. This ways linux.system.sudo pillar map to actual sudo attributes:

# simplified template:
Cmds_Alias {{ alias }}={{ commands }}
{{ user }}   {{ hosts }}=({{ runas }}) NOPASSWD: {{ commands }}
%{{ group }} {{ hosts }}=({{ runas }}) NOPASSWD: {{ commands }}

# when rendered:
saltuser1 ALL=(ALL) NOPASSWD: ALL

Linux with package, latest version:

Linux with package from certail repo, version with no upgrades:

Linux with package from certail repo, version with no GPG verification:

Linux with autoupdates (automatically install security package updates):

Managing cron tasks

There are two data structures that are related to managing cron itself and cron tasks:

and

linux:system:cron manages cron packages, services, and '/etc/cron.allow' file.

'deny' files are managed the only way - we're ensuring they are absent, that's a requirement from CIS 5.1.8

'cron' pillar structure is the following:

To add user to '/etc/cron.allow' use 'enabled' key as shown above.

'/etc/cron.deny' is not managed as CIS 5.1.8 requires it was removed.

A user would be ignored if any of the following is true: * user is disabled in linux:system:user:<username> * user is disabled in linux:system:cron:user:<username>

linux:system:job manages individual cron tasks.

By default, it will use name as an identifier, unless identifier key is explicitly set or False (then it will use Salt's default behavior which is identifier same as command resulting in not being able to change it):

Managing 'at' tasks

Pillar for managing at tasks is similar to one for cron tasks:

To add a user to '/etc/at.allow' use 'enabled' key as shown above.

'/etc/at.deny' is not managed as CIS 5.1.8 requires it was removed.

A user will be ignored if any of the following is true: * user is disabled in linux:system:user:<username> * user is disabled in linux:system:at:user:<username>

Linux security limits (limit sensu user memory usage to max 1GB):

Enable autologin on tty1 (may work only for Ubuntu 14.04):

To disable set autologin to false.

Set policy-rc.d on Debian-based systems. Action can be any available command in while true loop and case context. Following will disallow dpkg to stop/start services for the Cassandra package automatically:

Set system locales:

Systemd settings:

Ensure presence of directory:

Ensure presence of file by specifying its source:

Ensure presence of file by specifying its contents:

Ensure presence of file to be serialized through one of the serializer modules (see: https://docs.saltstack.com/en/latest/ref/serializers/all/index.html):

Kernel

Install always up to date LTS kernel and headers from Ubuntu Trusty:

Load kernel modules and add them to /etc/modules:

Configure or blacklist kernel modules with additional options to /etc/modprobe.d following example will add /etc/modprobe.d/nf_conntrack.conf file with line options nf_conntrack hashsize=262144:

'option' can be a mapping (with 'enabled' and 'value' keys) or a scalar.

Example for 'scalar' option value:

Example for 'mapping' option value:

NOTE: 'enabled' key is optional and is True by default.

Blacklist a module:

A module can have a number of aliases, wildcards are allowed. Define an alias for a module:

NOTE: 'enabled' key is mandatory as there are no other keys exist.

Execute custom command instead of 'insmod' when inserting a module:

NOTE: 'enabled' key is optional and is True by default.

Execute custom command instead of 'rmmod' when removing a module:

NOTE: 'enabled' key is optional and is True by default.

Define module dependencies:

NOTE: 'enabled' key is optional and is True by default.

Install specific kernel version and ensure all other kernel packages are not present. Also install extra modules and headers for this kernel:

Systcl kernel parameters:

Configure kernel boot options:

Alternative way to set kernel boot options:

CPU

Enable cpufreq governor for every cpu:

SELinux

Set SELinux mode on System:

CGROUPS

Setup linux cgroups:

Shared libraries

Set additional shared library to Linux system library path:

Certificates

Add certificate authority into system trusted CA bundle:

Sysfs

Install sysfsutils and set sysfs attributes:

Optional: You can also use list that will ensure order of items.

Sysfs definition with disabled automatic write. Attributes are saved to configuration, but are not applied during the run. Thay will be applied automatically after the reboot.

Note

The enable_apply parameter defaults to True if not defined.

Huge Pages

Huge Pages give a performance boost to applications that intensively deal with memory allocation/deallocation by decreasing memory fragmentation:

Note

Not recommended to use both pagesizes concurrently.

Intel SR-IOV

PCI-SIG Single Root I/O Virtualization and Sharing (SR-IOV) specification defines a standardized mechanism to virtualize PCIe devices. The mechanism can virtualize a single PCIe Ethernet controller to appear as multiple PCIe devices:

Isolate CPU options

Remove the specified CPUs, as defined by the cpu_number values, from the general kernel SMP balancing and scheduler algroithms. The only way to move a process onto or off an isolated CPU is via the CPU affinity syscalls. cpu_number begins at 0, so the maximum value is 1 less than the number of CPUs on the system.:

Repositories

RedHat-based Linux with additional OpenStack repo:

Ensure system repository to use czech Debian mirror (default: true) Also pin it's packages with priority 900:

If you need to add multiple pin rules for one repo, please use new,ordered definition format ('pinning' definition will be in priotity to use):

Note

For old Ubuntu releases (<xenial) extra packages for apt transport, like apt-transport-https may be required to be installed manually. (Chicken-eggs issue: we need to install packages to reach repo from where they should be installed) Otherwise, you still can try 'fortune' and install prereq.packages before any repo configuration, using list of requires in map.jinja.

Disabling any prerequisite packages installation:

You can simply drop any package pre-installation (before system.linux.repo will be processed) via cluster lvl:

Package manager proxy global setup:

Package manager proxy setup per repository:

Remove all repositories:

Refresh repositories metada, after configuration:

Setup custom apt config options:

RC

rc.local example

Prompt

Setting prompt is implemented by creating /etc/profile.d/prompt.sh. Every user can have different prompt:

On Debian systems, to set prompt system-wide, it's necessary to remove setting PS1 in /etc/bash.bashrc and ~/.bashrc, which comes from /etc/skel/.bashrc. This formula will do this automatically, but will not touch existing user's ~/.bashrc files except root.

Bash

Fix bash configuration to preserve history across sessions like ZSH does by default:

Login banner message

/etc/issue is a text file which contains a message or system identification to be printed before the login prompt. It may contain various @char and char sequences, if supported by the getty-type program employed on the system.

Setting logon banner message is easy:

Message of the day

pam_motd from package libpam-modules is used for dynamic messages of the day. Setting custom motd will clean up existing ones.

Setting static motd will replace existing /etc/motd and remove scripts from /etc/update-motd.d.

Setting static motd:

Setting dynamic motd:

Services

Stop and disable the linux service:

Possible statuses are dead (disable service by default), running (enable service by default), enabled, disabled:

Linux with the atop service:

Linux with the mcelog service:

RHEL / CentOS

Currently, update-motd is not available for RHEL. So there is no native support for dynamic motd. You can still set a static one, with a different pillar structure:

Haveged

If you are running headless server and are low on entropy, you may set up Haveged:

Linux network

Linux with network manager:

Execute linux.network.interface state without ifupdown activity:

Linux with default static network interfaces, default gateway interface and DNS servers:

Linux with bonded interfaces and disabled NetworkManager:

Linux with VLAN interface_params:

Linux with wireless interface parameters:

Linux networks with routes defined:

Native Linux Bridges:

Open vSwitch Bridges:

Debian manual proto interfaces

When you are changing interface proto from static in up state to manual, you may need to flush ip addresses. For example, if you want to use the interface and the ip on the bridge. This can be done by setting the ipflush_onchange to true.

Debian static proto interfaces

When you are changing interface proto from dhcp in up state to static, you may need to flush ip addresses and restart interface to assign ip address from a managed file. For example, if you wantto use the interface and the ip on the bridge. This can be done by setting the ipflush_onchange with combination restart_on_ipflush param set to true.

Concatinating and removing interface files

Debian based distributions have /etc/network/interfaces.d/ directory, where you can store configuration of network interfaces in separate files. You can concatinate the files to the defined destination when needed, this operation removes the file from the /etc/network/interfaces.d/. If you just need to remove iface files, you can use the remove_iface_files key.

Configure DHCP client

None of the keys is mandatory, include only those you really need. For full list of available options under send, supersede, prepend, append refer to dhcp-options(5).

Linux network systemd settings:

Configure global environment variables

Use /etc/environment for static system wide variable assignment after boot. Variable expansion is frequently not supported.

Configure the profile.d scripts

The profile.d scripts are being sourced during .sh execution and support variable expansion in opposite to /etc/environment global settings in /etc/environment.

Configure login.defs parameters

<opt_name> is a configurational option defined in 'man login.defs'. <opt_name> is case sensitive, should be UPPERCASE only!

Linux with hosts

Parameter purge_hosts will enforce whole /etc/hosts file, removing entries that are not defined in model except defaults for both IPv4 and IPv6 localhost and hostname as well as FQDN.

We recommend using this option to verify that /etc/hosts is always in a clean state. However it is not enabled by default for security reasons.

Linux with hosts collected from mine

All DNS records defined within infrastrucuture are passed to the local hosts records or any DNS server. Only hosts with the grain parameter set to true will be propagated to the mine.

Set up resolv.conf, nameservers, domain and search domains:

Set up custom TX queue length for tap interfaces:

Open vSwitch native bond:

DPDK OVS interfaces

DPDK OVS NIC

DPDK OVS Bond

DPDK OVS LACP Bond with vlan tag

DPDK OVS bridge for VXLAN

If VXLAN is used as tenant segmentation, IP address must be set on br-prv.

DPDK OVS bridge with Linux network interface

Linux storage

Linux with mounted Samba:

NFS mount:

File swap configuration:

Partition swap configuration:

LVM group vg1 with one device and data volume mounted into /mnt/data.

Create partitions on disk. Specify size in MB. It expects empty disk without any existing partitions. Set startsector=1 if you want to start partitions from 2048.

Multipath with Fujitsu Eternus DXL:

Multipath with Hitachi VSP 1000:

Multipath with IBM Storwize:

Multipath with multiple backends:

PAM LDAP integration:

PAM duo 2FA integration

duo package version may be specified (optional)

Disabled multipath (the default setup):

Linux with local loopback device:

External config generation

You are able to use config support metadata between formulas and only generate configuration files for external use, for example, Docker, and so on.

Netconsole Remote Kernel Logging

Netconsole logger can be configured for the configfs-enabled kernels (CONFIG_NETCONSOLE_DYNAMIC must be enabled). The configuration applies both in runtime (if network is already configured), and on-boot after an interface initialization.

Note

  • Receiver can be located only on the same L3 domain (or you need to configure gateway MAC manually).
  • The Receiver MAC is detected only on configuration time.
  • Using broadcast MAC is not recommended.

Check network params on the environment

Grab nics and nics states

Example of system output:

Grab 10G nics PCI addresses for hugepages setup

Example of system output:

Grab ip address for an interface

Example of system output:

Grab ip addresses map

Example of system output:

Verify full mesh connectivity

Example of positive system output:

Example of system output in case of failure:

For this feature to work, please mark addresses with some role. Otherwise 'default' role is assumed and mesh would consist of all addresses on the environment.

Mesh mark is needed only for interfaces which are enabled and have ip address assigned.

Checking dhcp pxe network meaningless, as it is used for salt master vs minion communications, therefore treated as checked.

Check pillars for ip address duplicates

Example of positive system output:

Example of system output in case of failure:

Generate csv report for the env

Example of system output:

Usage

Set MTU of the eth0 network interface to 1400:

Read more

Documentation and Bugs

About

License:Other


Languages

Language:SaltStack 64.4%Language:Shell 8.8%Language:HTML 8.4%Language:Python 7.5%Language:Scheme 6.8%Language:Makefile 3.0%Language:Ruby 1.2%