Security Smells in Ansible and Chef Scripts: a Replication Study
Total Page:16
File Type:pdf, Size:1020Kb
Security Smells in Ansible and Chef Scripts: A Replication Study AKOND RAHMAN, Tennessee Technological University, USA MD RAYHANUR RAHMAN, NC State University, USA CHRIS PARNIN, NC State University, USA LAURIE WILLIAMS, NC State University, USA Context: Security smells are recurring coding patterns that are indicative of security weakness, and require further inspection. As infrastructure as code (IaC) scripts, such as Ansible and Chef scripts, are used to provision cloud-based servers and systems at scale, security smells in IaC scripts could be used to enable malicious users to exploit vulnerabilities in the provisioned systems. Goal: The goal of this paper is to help practitioners avoid insecure coding practices while developing infrastructure as code scripts through an empirical study of security smells in Ansible and Chef scripts. Methodology: We conduct a replication study where we apply qualitative analysis with 1,956 IaC scripts to identify security smells for IaC scripts written in two languages: Ansible and Chef. We construct a static analysis tool called Security Linter for Ansible and Chef scripts (SLAC) to automatically identify security smells in 50,323 scripts collected from 813 open source software repositories. We also submit bug reports for 1,000 randomly-selected smell occurrences. Results: We identify two security smells not reported in prior work: missing default in case statement and no integrity check. By applying SLAC we identify 46,600 occurrences of security smells that include 7,849 hard-coded passwords. We observe agreement for 65 of the responded 94 bug reports, which suggests the relevance of security smells for Ansible and Chef scripts amongst practitioners. Conclusion: We observe security smells to be prevalent in Ansible and Chef scripts, similar to that of the Puppet scripts. We recommend practitioners to rigorously inspect the presence of the identified security smells in Ansible and Chef scripts using (i) code review, and (ii) static analysis tools. The paper is accepted at the journal of ACM Transactions on Software Engineering and Methodology (TOSEM) on June 20, 2020. CCS Concepts: • Security and privacy → Software security engineering. Additional Key Words and Phrases: ansible, chef, configuration as code, configuration scripts, devops, devsecops, empirical study, infrastructure as code, insecure coding, security, smell, static analysis ACM Reference Format: Akond Rahman, Md Rayhanur Rahman, Chris Parnin, and Laurie Williams. 2018. Security Smells in Ansible and Chef Scripts: A Replication Study. 1, 1 (June 2018), 31 pages. https://doi.org/10.1145/nnnnnnn.nnnnnnn 1 INTRODUCTION Infrastructure as code (IaC) is the practice of using automated scripting to provision and configure their development environment and servers at scale [16]. Similar to software source code, recommended software engineering practices, Authors’ addresses: Akond Rahman, Tennessee Technological University, 1 William Jones Drive, Cookeville, Tennessee, USA, [email protected]; Md Rayhanur Rahman, NC State University, 890 Oval Drive, Raleigh, North Carolina, USA, [email protected]; Chris Parnin, NC State University, 890 arXiv:1907.07159v2 [cs.CR] 20 Jun 2020 Oval Drive, Raleigh, North Carolina, USA, [email protected]; Laurie Williams, NC State University, 890 Oval Drive, Raleigh, North Carolina, USA, [email protected]. Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights forcomponents of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]. © 2018 Association for Computing Machinery. Manuscript submitted to ACM Manuscript submitted to ACM 1 2 Rahman et al. such as version control and testing are expected to be applied to implement the practice of IaC. IaC tool vendors, such as Ansible 1 and Chef 2 provide programming utilities to implement the practice of IaC. The use of IaC scripts has resulted in benefits for information technology (IT) organizations. For example, the use of IaC scripts helpedthe National Aeronautics and Space Administration (NASA) to reduce its multi-day patching process to 45 minutes [3]. Using IaC scripts application deployment time for Borsa Istanbul, Turkey’s stock exchange, reduced from ∼10 days to an hour [23]. With IaC scripts Ambit Energy increased their deployment frequency by a factor of 1,200 [32]. The Enterprise Strategy Group surveyed practitioners and reported the use of IaC scripts to help IT organizations gain 210% in time savings and 97% in cost savings on average [25]. Despite reported benefits, IaC scripts can be susceptible to security weakness. In our recent work, weidentified security smells for Puppet scripts [37]. Security smells are recurring coding patterns that are indicative of security weakness, and requires further inspection [37]. We identified 21,201 occurrences of seven security smells that include 1,326 occurrences of hard-coded passwords in 15,232 Puppet scripts. Our prior research showed relevance of the identified security smells amongst practitioners as well: from 212 responses we observe practitioners to agree with148 occurrences. IT organizations may use other languages, such as Ansible, Chef, and Terraform 3, for which our previous categoriza- tion of security smells reported in prior work [37] may not hold. A replication of our prior work for other languages, such as Ansible and Chef, may have value for practitioners as well as for research as we study the generalizability and robustness of IaC security smells in a larger variety of contexts. A 2019 survey with 786 practitioners reported Ansible as the most popular language to implement IaC, followed by Chef 45 . As usage of Ansible and Chef is getting increasingly popular amongst practitioners, identification of security smells could have relevance to practitioners in mitigating insecure coding practices in IaC. Our prior research [37] is not exhaustive and may not capture security smells that exist for other languages. Let us consider Figure1 in this regard. In Figure1, we present an actual Ansible code snippet downloaded from an open source software (OSS) repository 6. In the code snippet, we observe the ‘gpgcheck’ parameter is assigned ‘no’, indicating while downloading the ‘nginx’ package, the ‘yum’ package manager will not check the contents of the downloaded package 7. Not checking the content of a downloaded package is related to a security weakness called ‘Download of Code Without Integrity Check (CWE-494) 8’. According to Common Weakness Enumeration (CWE), not specifying integrity check may help malicious users to “execute attacker-controlled commands, read or modify sensitive resources, or prevent the software from functioning correctly for legitimate users”. Existence and persistence of security smells similar to Figure1 in IaC scripts provide attackers opportunities to attack the provisioned system. We hypothesize through a replication [45] of our prior work, we can systematically identify security smells for other languages namely, Ansible and Chef. The goal of this paper is to help practitioners avoid insecure coding practices while developing infrastructure as code scripts through an empirical study of security smells in Ansible and Chef scripts. We answer the following research questions: 1https://www.ansible.com/ 2https://www.chef.io/chef/ 3https://www.terraform.io/ 4https://info.flexerasoftware.com/SLO-WP-State-of-the-Cloud-2019 5https://www.techrepublic.com/article/ansible-overtakes-chef-and-puppet-as-the-top-cloud-configuration-management-tool/ 6https://git.openstack.org/cgit/openstack/openstack-ansible-ops/ 7https://docs.ansible.com/ansible/2.3/yum_repository_module.html 8https://cwe.mitre.org/data/definitions/494.html Manuscript submitted to ACM Security Smells in Ansible and Chef Scripts: A Replication Study 3 1 - name: Add nginx repo to yum sources list 2 yum_repository: 3 name:"nginx" 4 file:"nginx" Disabled ‘gpgcheck’: no integrity check 5 description:"NGINX repo" 6 baseurl:"{{ elastic_nginx_repo.repo}}" 7 state:"{{ elastic_nginx_repo.state}}" 8 enabled: yes 9 gpgcheck: no Fig. 1. An example Ansible script where integrity check is not specified. • RQ1: What security smells occur in Ansible and Chef scripts? • RQ2: How frequently do security smells occur for Ansible and Chef scripts? • RQ3: How do practitioners perceive the identified security smell occurrences for Ansible and Chef scripts? We build on prior research [37] related to security smells for IaC scripts on Puppet, and investigate what security smells for two languages used to implement the practice of IaC, namely Ansible and Chef. We conduct a differentiated replication [19][21] of our prior work [37], where we use a experimental setup different to our prior work using Ansible and Chef scripts. We apply qualitative analysis [54] on 1,101 Ansible scripts and 855 Chef scripts to determine security smells. Next, we construct a static analysis tool called Security Linter for Ansible and Chef scripts (SLAC)[37] to automatically identify the occurrence of these security smells in 14,253 Ansible and 36,070 Chef scripts collected by respectively, mining 365 and 448 OSS repositories.