GSA/DevSecOps-Mgmt-Tools-Deploy

Name: DevSecOps-Mgmt-Tools-Deploy

Owner: U.S. General Services Administration

Description: Deploys MGMT tools for the DevSecOps infrastructure

Created: 2017-09-05 18:37:50.0

Updated: 2017-12-15 19:33:36.0

Pushed: 2017-10-17 17:06:43.0

Homepage: null

Size: 30

Language: HCL

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

DevSecOps-Mgmt-Tools-Deploy

Base deployment for future DevSecOps environment management tools in AWS

This project implements the management toolset for a DevSecOps infrastructure. This deployment pairs well with DevSecOps-Infrastructure. This repo can be used against your own environment by setting the variables the way you want them, or left to the defaults to read a terraform remote state backend and deploy automatically to an environment that was created with the sister deployment.

This deployment uses several products and some Ansible roles to deploy tools. As of 09/06/17, it will deploy a Jenkins master instance with the GSA.jenkins Ansible role.

Products In Use
Important concepts
Configuration as code

All configuration is code, and all setup steps are documented. New environment(s) can be created from scratch quickly and reliably. The Jenkins deployment is using the baseline Ansible role created by GSA to deploy Jenkins in a default state. Please consult that repo for extra configuration instructions after deployment, especially if you wish to make modifications.

DRY

The code follows the Don?t Repeat Yourself (DRY) principle. Values that need to be shared are passed around as variables, rather than being hard-coded in multiple places. This ensures configuration stays in sync.

Setup

If you?ve already deployed the DevSecOps-Infrastructure repo, chances are you?ve already done some of this.

  1. Set up the AWS CLI on the workstation that will be used to deploy the code.

    1. Install
    2. Configure
  2. Install additional dependencies:

  3. Set up the Terraform backend for this deployment. Note that this is a different backend from others. We?ll refer to the remote state backend later. You will need to replace your bucket name with something unique, because bucket names must be unique per-region. If you get an error that the bucket name is not available, then your choice was not unique. Remember this bucket name, you?ll need it later.

    s3api create-bucket ?bucket <your_unique_bucket_name>
    s3api put-bucket-versioning ?<your_unique_bucket_name> ?versioning-configuration Status=Enabled
    
  4. Create the Terraform variables file.

    erraform
    erraform.tfvars.example terraform.tfvars
    ackends.tfvars.example backends.tfvars
    
  5. Fill out terraform.tfvars. Mind the variable types and follow the noted rules. Defaults are provided in vars.tfvars if you need examples or want to see where values are coming from.

  6. Fill out ?backends.tfvars?. The ?bucket? parameter must match the bucket name you used in the AWS CLI command above, otherwise terraform will throw an error on the init command.

  7. Set up an Ansible Vault with values that are secret and should not be stored in plain text on disk. Follow these steps if you wish to keep things as out of the box as possible. If you use different filenames, you will need to modify the Makefile.

  8. Generate an SSH key.

    keygen -t rsa -b 4096 -f temp.key -C "group-email+jenkins@some.gov"
    ter a passphrase - store in Vault as vault_jenkins_ssh_key_passphrase (see below)
    
    temp.key
    ore in Vault as vault_jenkins_ssh_private_key_data (see below)
    
    temp.key.pub
    ore as jenkins_ssh_public_key_data (see below)
    
    emp.key*
    
  9. Generate a self-signed SSL certificate or get one. You will need the private key and the certificate file to paste into the vault.

  10. Set up the required variables files that are specific to Jenkins/Ansible. Create the following directories:

    ible/group_vars
            |
            /all
            |
            /devsecops_mgmt_jenkins_master_eip
    

    Note that the directory “devsecops_mgmt_jenkins_master_eip” is set to this name to target the Jenkins master host that will be created. When the Ansible playbook is executed, terraform-inventory is called against the terraform.tfstate backend to obtain information about the host that was deployed. This keyboard is used to identify the instance that was created for Ansible to install Jenkins. You may wish to modify the playbook to meet your requirements.

    Fill out the file with the following data:

    oup_vars/devsecops_mgmt_jenkins_master_eip/vars.yml
    ins_external_hostname: <some-fqdn-hostname>
    ins_ssh_key_passphrase: "{{ vault_jenkins_ssh_key_passphrase }}"
    ins_ssh_private_key_data: "{{ vault_jenkins_ssh_private_key_data }}"
    certs_local_cert_data: "{{ vault_ssl_certs_local_cert_data }}"
    certs_local_privkey_data: "{{ vault_ssl_certs_local_privkey_data }}"
    ins_admin_username: <username for the admin user in web interface>
    ins_admin_password: "{{vault_jenkins_admin_password}}"
    ins_ssh_user: <username for ssh user>
    ins_ssh_public_key_data: |
    lic-key-data-from-above-steps>
    ins_java_options:
    

    “jenkins_java_options” overrides the geerlingguy.jenkins role to specify java_opt to pass along to Jenkins when running. Set heapsize or other options here, if they are needed. Note the use of variables preceded by “vault.” These variables must be defined in another file in this same directory. Create a new file called “vault.yml” with ansible-vault:

    ble-vault create vault.yml
    

    This command will ask for a password to encrypt the file and launch a text editor (likely vi). Fill out the variables like the example below.

    oup_vars/devsecops_mgmt_jenkins_master_eip/vault.yml (encrypted)
    t_jenkins_ssh_key_passphrase: ...(if one was used)
    t_jenkins_ssh_private_key_data: |
    ---BEGIN RSA PRIVATE KEY-----
    .(key data from above procedures)
    ---END RSA PRIVATE KEY-----
    t_ssl_certs_local_cert_data: |
    ---BEGIN CERTIFICATE-----
    .(paste SSL certificate info here)
    ---END CERTIFICATE-----
    t_ssl_certs_local_privkey_data: |
    ---BEGIN RSA PRIVATE KEY-----
    .(paste SSL certificate key info here)
    ---END RSA PRIVATE KEY-----
    t_jenkins_admin_password: <type a password here>
    

    Save the file in the text editor and then verify the encryption.

    If you wish, you can create another file called “.vault_pass.txt”. Store this file in the /ansible/playbooks directory. This file should contain the vault password on a line by itself. If you do not wish to store the vault password on disk, then you must modify the playbook file /ansible/playbooks/jenkins-master.yml and remove the command reference to the file. You can ask interactively for the password or store the password file elsewhere. For more details, consult the Ansible Vault documentation.

Deployment

For initial deployment, use the ansible make file to make things easier.

  1. Set up environment. For your convenience, terraform commands are provided in the ansible Makefile. If you?re confident in your variable-fu, you can just kick off the ?make? command and build the architecture from scratch. This will install all of the necessary roles,

    nsible
    
    

    This will run all of the commands in order. If you want to break things down into steps, you?re welcome to do them manually:

  2. make install_roles

  3. make init

  4. make plan

  5. make apply

  6. make install_jenkins

There is also a ?make debug? in the Makefile. This will run all of the steps the same way, except for the last one. It will run ?make install_jenkins_debug?, which will run ansible in full debug mode. Most problems will occur in variables, so pay careful attention to the variables and the values they expect.

There are two conditional variables noted in the file. If you leave the values blank, this deployment assumes that you deployed DevSecOps-Infrastructure in the same AWS environment. It will read the remote state backend (hopefully you configured that in the same variables file) and adjust the variable to place it in the public subnet of ?VPC-mgmt? from that deployment. If you wish to override this condition, simply specify a vpc_id and subnet_id as noted in the file.

?make destroy? will destroy the environment should you wish. You will have to confirm before it will actually destroys anything.

Notes

This deployment will automatically install the GSA.Jenkins role and all dependencies. Those roles will be downloaded during the ?make install_roles? phase. The roles will be install in ?/ansible/roles/external?.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.