Excellent Generic Troubleshooting Tips for I.T. work (e.g., DevOps tasks)

At the time of writing, we suggest these troubleshooting steps for many I.T. tasks. Some of these will not apply to every problem. But if you do not know where to begin, this can help you with "DevOps block."

1. Find the word "error" in the logs. Look at a log with vi (e.g., copy the log to a location where it will not be continually written to). Open the copy with vi. Run this command:
:set ignorecase

Search for the word "error"

2. Reboot the server and try again.

3. Find one server or program that works, see how it is different from the one that fails.

4. Start over from the beginning (redeploy).

5. Find what changed since it was last working. If it never worked, try to deploy it on a different distribution of Linux.

6. If the problem is reproducible, try to isolate the problem. A back-to-basics approach can involve reducing problems to atomic parts. From there you can diagnose an underlying component having a problem and thus find a solution.

What is a Container Breakout?

Question
What is a container breakout?

Answer
A container breakout is an the act of a user or process in a container gaining access to its underlying host server. Containerization is the isolation of processes and/or disk space on a server. A container is isolated from the host server via cgroups and namespaces. Bypassing the cgroup(s) and namespace(s) through intentional acts can be desirable for legitimate systems engineers. While such an operation can denote a "breakout", we find the term "container breakout" to connote the unauthorized circumvention of the isolating cgroups and namespaces. Some Docker hosts and configurations of containers can be exploited by hackers. Thus a new big security concern in the I.T. world is the "container breakout" or "Docker [container] breakout".

To see the term in context, read these examples:

https://www.oreilly.com/library/view/advanced-infrastructure-penetration/9781788624480/5603d194-56b9-4815-8627-439f262d6d15.xhtml

https://news.ycombinator.com/item?id=7909622

https://hub.docker.com/r/gabrtv/shocker/

Page 3 of this PDF uses the term.

https://blog.docker.com/2014/06/docker-container-breakout-proof-of-concept-exploit/

If you want to learn how to secure a Docker container, see this posting.

Do the Credentials “****” in Jenkins, Taken from the Credentials Plugin, Have the Username or the Password?

Problem Scenario
You want to use the credentials from the Jenkins credentials plugin in a Jenkins pipeline. When you assign the credentials to a variable in a pipeline, is it the username, the password, both or something else?

Solution
It is the username and password, but the two are separated by a colon. You will only see "****" in the console output (for security reasons). Here is an example: jdoe:goodP@$$w0rd!

The above is an example with a username of jdoe and a password of goodP@$$w0rd!

How Do You Troubleshoot the Message “ImportError: cannot import name ‘pubsub_v1′”?

Problem scenario
From the Python command prompt or when running a Python program, you receive this message "ImportError: cannot import name 'pubsub_v1'". What should you do?

Solution
Possible Solution #1
Try to run the program as sudo: sudo python nameOfProg.py

Possible Solution #2
Prerequisite
This assumes that pip has been installed. If you need assistance see this posting "How Do You Install pip?".

Procedure
Try this with or without sudo (depending on whether or not you are using "sudo" to run the Python program):

sudo pip install google-cloud-pubsub
# You may want to omit the "sudo" in the above command.

Possible Solution #3
Prerequisite
This assumes that pip has been installed. If you need assistance see this posting "How Do You Install pip?".

sudo pip uninstall google-cloud-pubsub
sudo pip install google-cloud-pubsub

# You may or may not want to omit the "sudo" in the above commands.

What is a Jenkins Executor?

Question
What is a Jenkins executor?

Answer
It is a designation in the Jenkins master server's settings that governs resource allocation (e.g., CPU and RAM) on any Jenkins nodes and the master server itself. When a server (either the master or a node) is designated as having two or more executors, the server can process as many jobs simultaneously as the number of executors for which it has been designated.

In other words if a server has been configured to have three executors, this server can process three jobs concurrently. If the server has been configured to have one or zero executors, then the server can process only one Jenkins job.

The verbatim definition on the Jenkins website of an executor is as follows:
"A slot for execution of work defined by a Pipeline or Project on a Node. A Node may have zero or more Executors configured which corresponds to how many concurrent Projects or Pipelines are able to execute on that Node."

An executor is a subprocess of a main process on a Jenkins node (according to this posting).

How Do You Use the seq Reserved Word in a Bash Script to Generate Content for a File?

Problem scenario
You want to rapidly create hundreds of lines of text for a file. You want to do some testing and you need a file you can delete. You also want to use the seq keyword.

Solution
Here is a program that uses the seq keyword:

#!/bin/bash
COUNTER=100

for varnum in `seq $COUNTER`
do
  date >> goodfile
  echo $varnum >> goodfile
done

Some people recommend not using the seq keyword. An alternative way of writing the above is this:

#!/bin/bash

for varnum in {1..100}
do
  date >> goodfile
  echo $varnum >> goodfile
done

You notice the {1..100} is more terse with no COUNTER variable assignment.

How Do You Troubleshoot the Message “ImportError: No module named ‘google'”?

Problem scenario
From the Python command prompt or when running a Python program, you receive this message "ImportError: No module named 'google'". What should you do?

Solution
Possible Solution #1
Try to run the program as sudo: sudo python nameOfProg.py

Possible Solution #2
Prerequisite
This assumes that pip has been installed. If you need assistance see this posting "How Do You Install pip?".

Procedure
Try this with or without sudo (depending on whether or not you are using "sudo" to run the Python program):

sudo pip install protobuf
# You may want to omit the "sudo" in the above command.

Possible Solution #3
Prerequisite
This assumes that pip has been installed. If you need assistance see this posting "How Do You Install pip?".

Procedures
Run these commands:

sudo pip uninstall protobuf
sudo pip install protobuf

# You may or may not want to omit the "sudo" in the above commands.

What Common Utility Can Provide Compression and Encryption for Files on Linux and How Would You Use It?

Problem scenario
You want to use the same command for encryption and compression. You want to avoid installing other packages. What should you do?

Solution
Use zip. The tar command by itself does NOT do compression (according to this external posting).

One advantage of zip is that it is usually pre-installed on most Linux servers. The user and group of the files thus compressed will be retained automatically.

Draft a zip command like the one below. Replace "goodfile" with the file you want to be copied into a compressed and encrypted copy. Replace "good.zip" with the name of the new compressed & encrypted file you want the command to create.

zip --encrypt good.zip goodfile # This command will prompt you for a password. Remember the password.

# Run the command after it is drafted according to the directions above.

You can move a copy to a different directory, then run this command to extract a regular version of this file that was encrypted and compressed in good.zip:

unzip good.zip # Where "good.zip" is the name of the .zip file.

If you only need to encrypt, see this external page for examples of different tools. (However, beware of drawbacks of GPG and openssl. This link provides some relevant warnings.)

If you only need to compress, see this external page for examples of different tools.

A List of I.T. Security Books

This is a list of I.T. Security books.

Applied Cryptography: Protocols, Algorithms and Source Code in C

Building Secure and Reliable Systems: SRE and Security Best Practices

Database Security

Defend I.T.: Security by Example

Hack I.T. - Security Through Penetration Testing

Hacking Exposed Web Applications, Third Edition

Hacking Web Apps: Detecting and Preventing Web Application Security Problems

Hadoop Security: Protecting Your Big Data Platform

Hands-On Security in DevOps: Ensure continuous security, deployment, and delivery with DevSecOps

Identity and Data Security for Web Development: Best Practices

Implementing Database Security and Auditing

Internet Security: How to Defend Against Attackers on the Web (Jones & Bartlett Learning Information Systems Security & Assurance)

Linux Hardening in Hostile Networks: Server Security from TLS to Tor (Pearson Open Source Software Development Series)

Mastering Linux Security and Hardening: Secure your Linux server and protect it from intruders, malware attacks, and other external threats

Microsoft Windows Security Essentials

Multilevel Security for Relational Databases

Network Security Through Data Analysis: From Data to Action

Oracle Database 12c Security

The Penetration Tester's Guide to Web Applications (Artech House Computer Security Series)

Practical Web Penetration Testing: Secure web applications using Burp Suite, Nmap, Metasploit, and more

Pro ASP.NET Web API Security: Securing ASP.NET Web API (Expert's Voice in .NET)

Securing DevOps: Security in the Cloud

Security for Web Developers: Using JavaScript, HTML, and CSS

The Tangled Web: A Guide to Securing Modern Web Applications

The Web Application Hacker's Handbook: Finding and Exploiting Security Flaws

Web Application Security is a Stack: How to CYA (cover your apps) completely

Web Security

Web Security Testing Cookbook: Systematic Techniques to Find Problems Fast

Web Services Security

Windows Security Monitoring: Scenarios and Patterns

**********************************

For Docker container hardening, see this link.

How Do You use the Built-in Exception Handling Functionality of Python?

Problem scenario
You want to use the built-in exception handling in your Python program. You know some part or parts of the code may throw an error. How do you use the "except" keyword?

Solution
Use the "try" key word. Here is an example of a program that throws an error:

commandthatdoesnotexist
 x = 1 + 1
 print(x)

python3 progwitherror.py
Traceback (most recent call last):
File "progwitherror.py", line 1, in
commandthatdoesnotexist
NameError: name 'commandthatdoesnotexist' is not defined

Here is a re-write of the same program with the "except" keyword:

try:
   commandthatdoesnotexist
 except NameError:
   print("Got into this exception.  Program will continue")
x = 1 + 1
print(x)

Here is the output of the program after it runs:

Got into this exception. Program will continue
2

There are many other errors beside "NameError" that can be supported by except.

With "SyntaxError", it does not catch any Syntax Error. It only catches those arising from eval, exec or import (as explained here).

If you want to learn more about the except feature, see this external posting.