DevOps.com

Where the world meets DevOps

  • Latest
    • Articles
    • Features
    • Most Read
    • News
    • News Releases
  • Topics
    • AI
    • Continuous Delivery
    • Continuous Testing
    • Cloud
    • Culture
    • DevSecOps
    • Enterprise DevOps
    • Leadership Suite
    • DevOps Practice
    • ROELBOB
    • DevOps Toolbox
  • Chat
  • Webinars
    • Upcoming
    • On-Demand Webinars
  • Library
  • Events
    • Virtual Summits
    • Conferences
  • Sponsored Communities
    • CloudBees
  • Related Sites
    • MediaOps
    • Container Journal
    • Security Boulevard
    • SweetCode.io
    • Digital Anarchist
    • DevOps TV on YouTube
    • DevOps Chat on SoundCloud
    • DevOps Connect
    • DevOps Dozen
  • Follow Us
    • Twitter
    • Google News
    • LinkedIn
    • Facebook
    • DevOps TV on YouTube
    • Email
MENUMENU
  • AI
    • Testim

      Testim Adds SDK to AI-Based Testing Platform

      IBM AI

      IBM Zones in on DevOps for AI

      Virtana

      Virtual Instruments Changes Name to Virtana to Drive AIOps

      AIOps for Mission Critical Workloads

      What is so Special About AIOps for Mission Critical Workloads?

      Continuous Optimization

      Continuous Optimization: An Idea Whose Time Has Come?

  • Cloud
    • Investing Mobile Device Testing Lab

      Investing in a Mobile Device Testing Lab

      Build Reliable App

      What It Really Takes to Build a Reliable App

      Serverless and GraphQL

      Serverless and GraphQL: Build and Launch at the Speed of Thought

      How Organizations Benefit from AWS App Patterns

      How Organizations Benefit from AWS App Patterns

      Accelerating Cloud Wars

      The Accelerating Cloud Wars

  • Continuous Delivery
    • Harness

      Harness Adds Analytics to CDaaS Platform

      Dell Boomi Dives Into DevOps

      Dell Boomi Dives Into DevOps

      Implement an Effective CI/CD Pipeline

      How to Implement an Effective CI/CD Pipeline

      CloudBees continuous delivery

      CloudBees Advances Continuous Delivery

      OverOps

      OverOps Integrates AI Code Analyzer With CI/CD Platforms

  • Continuous Testing
    • Investing Mobile Device Testing Lab

      Investing in a Mobile Device Testing Lab

      IBN’s Success is Driven by Formulating the Right Test Validation Strategy

      IBN’s Success is Driven by Formulating the Right Test Validation Strategy

      Steps to Ensuring Validity of Your Business-Critical Data

      5 Steps to Ensuring Validity of Your Business-Critical Data

      Agile and DevOps Success Needs Continuous Testing

      Agile and DevOps Success Needs Continuous Testing

      How Continuous Testing Advances Your Business Goals

      How Continuous Testing Advances Your Business Goals

  • DevSecOps
    • Three Ways Developers Can Worry Less About Security

      Three Ways Developers Can Worry Less About Security

      Engineering Approach to DevOps

      The Time Has Come for an Engineering Approach to DevOps

      AWS Application Patterns

      What Are AWS Application Patterns?

      DevSecOps

      Survey Surfaces Uneven Approaches to DevSecOps

      Breaking Down the OWASP API Security

      Breaking Down the OWASP API Security Top 10, Part 1

  • Leadership Suite
    • Solving Technology Skills Gap

      Five Tips for Solving the Technology Skills Gap

      developers

      Developers Are Gaining Clout, and We Need to Pay Attention

      Accelerating Cloud Wars

      The Accelerating Cloud Wars

      ServiceNow, Salesforce and Atlassian Work Together

      Crossing the Ecosystem Boundaries: How ServiceNow, Salesforce and Atlassian Work Together

      CIOs See Dramatic Change Ahead

      CIOs See Dramatic Change Ahead

  • Practices
    • Success of Software Deployments

      Operational Excellence and the Success of Software Deployments

      ServiceNowDevOps

      ServiceNow Makes the DevOps Connection

      Investing Mobile Device Testing Lab

      Investing in a Mobile Device Testing Lab

      Solving Technology Skills Gap

      Five Tips for Solving the Technology Skills Gap

      IT Scale Digital Transformation

      IT Enables Scale in Digital Transformation

  • ROELBOB
    • aspects-of-intimacy

      Aspects of Intimacy

      unintended-consequences

      Unintended Consequences

      Dev-Prod Parity in the Real World

      Dev-Prod Parity in the Real World

      employment-benefits

      Employment Benefits

      self-importance

      A Matter of Self-Importance

  • Toolbox
    • ServiceNowDevOps

      ServiceNow Makes the DevOps Connection

      Testim

      Testim Adds SDK to AI-Based Testing Platform

      The Power of Embedded Analytics and the Build Versus Buy Dilemma

      The Power of Embedded Analytics and the Build Versus Buy Dilemma

      How Organizations Benefit from AWS App Patterns

      How Organizations Benefit from AWS App Patterns

      Engineering Approach to DevOps

      The Time Has Come for an Engineering Approach to DevOps

  • More Topics
    • Application Performance Management/Monitoring
    • Culture
    • Enterprise DevOps

Home » Blogs » DevSecOps » Security automation with DevOps: show me the code!

Security automation with DevOps: show me the code!

By Rich Mogull on May 7, 2014 1 Comment

Last week Andrew Storms put up a good post hinting at the promise of security automation in [SecDevOps: Security Automation By Example – The Firewall Change]. He included an example of automating a series of actions when a firewall rule is changed. It’s a good article, although I’m increasingly convinced there’s no such thing as SecDevOps. In my book, it’s all DevOps, but that’s fodder for another post (when I’m not battling a stomach bug). However, what Andrew describes is more of what I consider an automated assist. It isn’t necessarily full automation, since it triggers on a manual firewall rule change. Ideally we rarely manually change a firewall (or Security Group) rule, and rely more on self-configuring based on policies. Yeah, I know, the usual analyst BS, so here’s a bit of process, and a bit of code. Let’s approach this differently. Take Andrew’s process, but let’s have the security group or host firewall self configure based on the asset. My example is going to be Amazon Web Services specific, since I have some code snippets to show off how it works. (Sorry, I don’t have the time or intestinal fortitude to write out all the code today; seriously, where did this bug come from?!?) There are two techniques I generally see forming the core of dynamic Security Group policy enforcement:

Recent Posts By Rich Mogull
  • Building Great Cloud Security Guardrails
  • Cloud Security: Software Defined. Event Driven. Awesome.
  • Hacking Your Auditor
More from Rich Mogull
Related Posts
  • SecDevOps: Security Automation By Example – The Firewall Change
  • Deputizing Everyone for Security – Building Agile Assurance
  • What is Security Policy Orchestration and Why Should DevOps Teams Care?
    Related Categories
  • Blogs
  • DevSecOps
    Related Topics
  • Amazon
  • automation
  • AWS
  • Chef
  • devops
  • Puppet
  • secdevops
  • security
  • tools
Show more
Show less
  1. Tags
  2. Configuration Management integration

Some cloud services, like AWS, support tags at the object (in this case, instance) level. These tags can tie internally to policies while also being consumable for external tools. Here is a policy I use that restricts access to an object if the “SecurityStatus” tag is “IR” (for “Incident Response”):

{  
  "Version": "2012-10-17",  
  "Statement": [  
    {
      "Action": "*",
      "Condition": {  
        "StringEquals": {
          "ec2:ResourceTag/SecurityStatus": "IR"
          }
          },
          "Resource": [
          "*"
                      ],
          "Effect": "Deny"
      }
      ]  
    }         

I could apply that tag manually or automatically, and in either case the instance can no longer be managed by any account this policy is applied to. Now this doesn’t help us change firewall/Security Group rules, since you can’t manage those directly in EC2 based on tags (but I had the policy handy to demo, so there you go). For that to work, you need to write your own code to scan for tags and then take actions. I don’t have exactly the right code examples on hand. but here are some snippets to get you close. Most of these are cribbed from my SecuritySquirrel proof of concept on GitHub. They are all in Ruby, using the AWS 2.0 developer preview SDK. First, to pull a list of all instances with a certain tag, you can use the following:

def testing
 # testing some tag code
 instancelist = @@ec22.describe_tags(
 filters: [
 {
   name: "key",
   values: ["SecurityStatus"]
 }
 ]
 )
 puts instancelist.to_h
end  

That shows everything with the SecurityStatus tag (instances and values, shown as a hash), but you could also filter on value. From there, you could pull the instance IDs with a map (you might want to further filter only on instances, but if you made it this far you can figure that out):

 instances = instancelist.map(&:resource_id)  

Then you can pump those into a method to change the Security Group. Here’s the one from SecuritySquirrel that places an instance into a “Quarantine” group:

def quarantine
  #this method moves the provided instance into the Quarantine security group defined in the config file.
  puts ""
  puts "Quarantining #{@instance_id}..."
  quarantine = @@ec22.modify_instance_attribute(instance_id: "#{@instance_id}", groups: ["#{@QuarantineGroup}"])
  puts "#{@instance_id} moved to the Quarantine security group from your configuration settings."
end  

Want to trigger some scanning? Here’s a code snippet to trigger a Qualys scan on an instance from a virtual appliance in your AWS account (keep in mind, I’m skipping a bunch of important pieces, like configuring the service and authenticating):

  instance_IP = instance_details.reservations.first.instances.first.private_ip_address
 timestamp = Time.new
 scan =(HTTParty.post("https://qualysapi.qg2.apps.qualys.com/api/2.0/fo/scan/",
      :basic_auth => @qualysauth,
      :query => { 
        :action => "launch",
        :scan_title => "SecuritySquirrel Scan at #{timestamp}", 
        :ip => "#{instance_IP}",
        :option_title => "Initial Options",
        :iscanner_name =>  "us-west-2" 
      },
      :headers => { "X-Requested-With" => "ruby httparty"}))
      puts "Launching Qualys scan named: SecuritySquirrel Scan at #{timestamp}"  

Or want to change the CloudPassage Halo host firewall rules? Well, that code uses a pre-release of their Ruby SDK, so I’ll save it for another day (I’m not employed by them, but they let me play with the pre-release gem). These examples are all based on tags, but remember that if you use a tool like Chef or Puppet you can do the exact same thing based on what software is configured and running within the instance. For example, you could create a policy to quarantine all SSL when the Heartbleed vulnerability hit by closing off port 443 on any server running the vulnerable OpenSSL package, then remove the rule when it is updated to the patched version. I’m a bit rusty since I don’t code every day, but I could probably pop that code off in an hour or two, it isn’t that hard. Also my tool is designed for demos, and doesn’t run in the background, but clearly you could have it running all the time, adjusting things based on tags or even attributes of software deployed in the instance. Security automation is insanely powerful. It can completely automate complex security tasks, or, as in Andrew’s example, supplement manual activities and policy changes. Hopefully my snippets give you some ideas, and pop me over any good examples if you are willing to share.

Filed Under: Blogs, DevSecOps Tagged With: Amazon, automation, AWS, Chef, devops, Puppet, secdevops, security, tools

  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to share on Facebook (Opens in new window)
  • Click to share on Reddit (Opens in new window)
  • More
  • Click to share on Pinterest (Opens in new window)
  • Click to share on Tumblr (Opens in new window)

Like this:

Like Loading...
Sponsored Content
Featured eBook
Optimize DevOps with Application Release Orchestration

Optimize DevOps with Application Release Orchestration

Digital transformation is ubiquitous. Getting quality software into production quickly and efficiently is a major priority for organizations of all types. Yet many find that development teams’ agile pace of software delivery and new technology adoption has outstripped the ability of operations teams to keep up. This cadence and skills ... Read More
« DevOps resilience: going active-active with an existing application
Automation, Operations, DevOps – What We Thought Was Missing »

Live Coverage: KubeCon | CloudNativeCon, San Diego, CA

Click Play to Watch the Digital Anarchist Live Coverage.

Top Stories of the Week

  • View DevOps.com Privacy Policy

Latest from DevOps.com

Operational Excellence and the Success of Software Deploymen...
November 19, 2019 | Chris Tozzi
2019 DevOps Dozen Finalists Announced
November 19, 2019 | Alan Shimel
DevOps Chat: Robotic Process Automation with Tricentis
November 19, 2019 | Mitchell Ashley
ServiceNow Makes the DevOps Connection
November 18, 2019 | Mike Vizard
Investing in a Mobile Device Testing Lab
November 18, 2019 | Dan McFall

Most Read on DevOps.com

2019 DevOps Dozen Finalists Announced
November 19, 2019 | Alan Shimel
Five Microservices Worst Practices
November 13, 2019 | Eric Schabell
Dev-Prod Parity in the Real World
November 13, 2019 | ROELBOB
Serverless and GraphQL: Build and Launch at the Speed of Tho...
November 13, 2019 | Brecht De Rooms
WhiteSource Acquires Renovate to Automate Dependency Updates
November 13, 2019 | Mike Vizard

Upcoming Webinars

Thu 21

Igniting Your Digital Transformation With Microservices