DevOps.com

Where the world meets DevOps

  • Latest
    • This Week in DevOps
    • 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
    • Virtual Instruments Aims to Meld DevOps, ITSM Worlds

      Virtual Instruments Aims to Meld DevOps, ITSM Worlds

      Computer Vision is Building the Future

      Computer Vision is Building the Future

      OverOps

      OverOps Integrates AI Code Analyzer With CI/CD Platforms

      Fujitsu State of Digital Transformation

      Fujitsu: State of Digital Transformation Is…Mixed

      With Platform, Dotscience Applies DevOps to AI

      With Platform, Dotscience Applies DevOps to AI

  • Cloud
    • Should Your Company Use DBaaS

      Should Your Company Use DBaaS?

      Why Integration Must Be Hybrid

      Why Integration Must Be Hybrid

      Cloud Foundry

      Survey Sees Cloud Foundry Momentum Gains

      Fugue

      Cloud Security: Self-Healing Infrastructure With Fugue

      Atlassian cloud

      Atlassian Looks to the Cloud

  • Continuous Delivery
    • CloudBees continuous delivery

      CloudBees Advances Continuous Delivery

      OverOps

      OverOps Integrates AI Code Analyzer With CI/CD Platforms

      CircleCI Extends CI/CD Reach to Windows Platforms

      CircleCI Extends CI/CD Reach to Windows Platforms

      Armory Looks to Drive Enterprise Adoption of Spinnaker

      Armory Looks to Drive Enterprise Adoption of Spinnaker

      Armory DevOps Chat

      DevOps Chat: Armory Discusses $28M Funding, Continuous Delivery

  • Continuous Testing
    • 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

      CloudBees' Acquisition of Rollout: The CEOs' View

      CloudBees’ Acquisition of Rollout: The CEOs’ View

  • DevSecOps
    • IoT Security Concerns

      IoT Security Concerns

      DevOps Chat: Splunk Moves Into Microservices With Omnition Buy

      DevOps Chat: Splunk Moves Into Microservices With Omnition Buy

      Fugue

      Cloud Security: Self-Healing Infrastructure With Fugue

      From DevOps to DevSecOps: Owning Cloud Security

      From DevOps to DevSecOps: Owning Cloud Security

      VMware DevSecOps

      VMware Starts to Make DevSecOps Case

  • Leadership Suite
    • Key Skills Developers Need to Master

      5 Key Skills Developers Need to Master in Order to Thrive

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

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

      Legacy Systems Prove to be Digital Transformation Headwind

      Legacy Systems Prove to be Digital Transformation Headwind

      Agile Methodologies Work for IT Infra

      Does Agile Methodologies Work for IT Infra?

      Overcome Resistance to DevOps Implementation

      How to Overcome Resistance to DevOps Implementation

  • Practices
    • Should Your Company Use DBaaS

      Should Your Company Use DBaaS?

      Why Integration Must Be Hybrid

      Why Integration Must Be Hybrid

      Feature Monitoring to Feature Delivery Toolset

      Split Software Adds Feature Monitoring to Feature Delivery Toolset

      IoT Security Concerns

      IoT Security Concerns

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

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

  • ROELBOB
    • history-of-computing-editors

      The History of Computing, Part 4: Code Editors

      bedtime-story

      Bedtime Story

      CRUD

      Create Read Update Delete

      comparative-tech

      Comparative Technology

      History-of-Incident-Management-Part-1

      History of Incident Management – Part 1

  • Toolbox
    • Feature Monitoring to Feature Delivery Toolset

      Split Software Adds Feature Monitoring to Feature Delivery Toolset

      Deadline Extended! Get Your Tools Included in Our DevOps Tools Directory

      Deadline Extended! Get Your Tools Included in Our DevOps Tools Directory

      Why COBOL Still Matters After 60 Years

      Why COBOL Still Matters After 60 Years

      Bedrock of Digital Transformation

      The Bedrock of Digital Transformation

      DevOps Dozen 2019 Nominations Are Now Open

      DevOps Dozen 2019 Nominations Are Now Open

  • 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,