Skip to content

Commit 32fa638

Browse files
committed
Add dockerfile for development testing. And some scripts and documentation for testing functionality against ADDS/DNS/NTP/KERBEROS
1 parent 4501849 commit 32fa638

12 files changed

+1048
-0
lines changed

CONTRIBUTING.md

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# smart_proxy_realm_ad_plugin
2+
3+
Welcome to the project! This repository contains smart_proxy_realm_ad_plugin.
4+
5+
## Getting Started
6+
7+
For detailed onboarding instructions, please refer to the [ONBOARDING.md](ONBOARDING.md) file.
8+
9+
## Prerequisites
10+
11+
- Docker
12+
- Git
13+
14+
## Quick Start
15+
16+
1. **Clone your fork**
17+
18+
```sh
19+
git clone https://github.com/your-username/smart_proxy_realm_ad_plugin.git
20+
cd smart_proxy_realm_ad_plugin
21+
```
22+
23+
2. **Install the prerequisites**
24+
25+
Ensure you have Docker and Git installed on your machine. You can follow the official installation guides:
26+
27+
- [Docker Installation](https://docs.docker.com/get-docker/)
28+
- [Git Installation](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
29+
30+
3. **Build the Docker image**
31+
32+
Use Docker to build the image for the development environment.
33+
34+
```sh
35+
docker build -t smart_proxy_realm_ad_plugin .
36+
```
37+
38+
4. **Run the Docker container**
39+
40+
Start the Docker container with the necessary configurations.
41+
42+
```sh
43+
docker run -it --rm --name smart_proxy_realm_ad_plugin -v $(pwd):/app -w /app smart_proxy_realm_ad_plugin
44+
```
45+
46+
This command will run the Docker container interactively, mount the current directory to `/app` inside the container, and set the working directory to `/app`.
47+
48+
5. **Install dependencies**
49+
50+
Inside the running Docker container, install the necessary dependencies.
51+
52+
```sh
53+
bundle install
54+
```
55+
56+
6. **Run tests**
57+
58+
To ensure everything is set up correctly, you can run the tests inside the Docker container.
59+
60+
```sh
61+
bundle exec rake test
62+
```
63+
64+
7. **Start developing**
65+
66+
You are now ready to start developing! Make your changes and see them reflected in the running application.
67+
68+
## Additional Resources
69+
70+
- [Foreman Documentation](https://theforeman.org/documentation.html)
71+
- [Foreman Smart Proxy Documentation](https://theforeman.org/manuals/latest/index.html#4.3SmartProxies)
72+
- [Foreman Community](https://community.theforeman.org/)
73+

Dockerfile

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
FROM ubuntu:22.04
2+
3+
# Define package lists
4+
ENV RUBY_PACKAGES="ruby ruby-dev gem"
5+
ENV BUILD_TOOLS="automake autoconf gcc make libc-dev"
6+
ENV RADCLI_DEPENDENCIES="libkrb5-dev libldap2-dev libsasl2-dev"
7+
ENV TESTING_TOOLS="adcli krb5-user ldap-utils dnsutils ltrace strace"
8+
ENV VERSION_CONTROL="git"
9+
ENV NETWORK_TOOLS="iputils-ping nmap tshark"
10+
ENV UTILITY_TOOLS="wget gnupg sudo"
11+
12+
# Define DNS resolver variables
13+
ENV DNS_SERVER=192.168.3.1
14+
ENV DNS_SEARCH=lab.local
15+
ENV DOMAIN="lab.local"
16+
17+
# Preconfigure krb5-config and tshark to avoid interactive prompts
18+
RUN echo "krb5-config krb5-config/default_realm string LAB.LOCAL" | debconf-set-selections && \
19+
echo "resolvconf resolvconf/linkify-resolvconf boolean false" | debconf-set-selections && \
20+
echo "wireshark-common wireshark-common/install-setuid boolean true" | debconf-set-selections && \
21+
echo "wireshark-common wireshark-common/install-setuid boolean true" | debconf-set-selections
22+
23+
# Copy the DNS setup script
24+
COPY ./scripts/set_dns.sh /usr/local/bin/set_dns.sh
25+
RUN chmod +x /usr/local/bin/set_dns.sh
26+
27+
# Install packages
28+
RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
29+
apt-get install -y --no-install-recommends \
30+
$RADCLI_DEPENDENCIES \
31+
$RUBY_PACKAGES \
32+
$BUILD_TOOLS \
33+
$LIBRARIES \
34+
$TESTING_TOOLS \
35+
$NETWORK_TOOLS \
36+
$VERSION_CONTROL \
37+
$UTILITY_TOOLS && \
38+
rm -rf /var/lib/apt/lists/*
39+
40+
# Install foreman-proxy nightly
41+
RUN apt update && \
42+
apt install -y wget ca-certificates && \
43+
cd /tmp && wget https://apt.puppet.com/puppet7-release-jammy.deb && \
44+
apt install -y /tmp/puppet7-release-jammy.deb && \
45+
wget https://deb.theforeman.org/foreman.asc -O /etc/apt/trusted.gpg.d/foreman.asc && \
46+
echo "deb http://deb.theforeman.org/ jammy nightly" | tee /etc/apt/sources.list.d/foreman.list && \
47+
echo "deb http://deb.theforeman.org/ jammy nightly" | tee /etc/apt/sources.list.d/foreman.list && \
48+
echo "deb http://deb.theforeman.org/ plugins nightly" | tee -a /etc/apt/sources.list.d/foreman.list && \
49+
apt update -y && \
50+
apt upgrade -y
51+
52+
# Create a non-root user with sudo access
53+
RUN groupadd -r devuser && useradd -r -g devuser -m -s /bin/bash devuser && \
54+
usermod -aG sudo devuser && \
55+
echo "devuser ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
56+
57+
# Set the user to the newly created non-root user
58+
USER devuser
59+
60+
# Set the working directory
61+
WORKDIR /home/devuser
62+
63+
# Install oh-my-bash for devuser
64+
RUN git clone https://github.com/ohmybash/oh-my-bash.git /home/devuser/.oh-my-bash && \
65+
cp /home/devuser/.oh-my-bash/templates/bashrc.osh-template /home/devuser/.bashrc && \
66+
chown -R devuser:devuser /home/devuser/.oh-my-bash /home/devuser/.bashrc
67+
68+
WORKDIR /app
69+
70+
# Set the entrypoint to the DNS setup script
71+
ENTRYPOINT ["/usr/local/bin/set_dns.sh"]
72+
CMD ["/bin/bash"]

Makefile

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
IMAGE_NAME=smart_proxy_realm_ad_plugin:master
2+
CONTAINER_NAME=smart_proxy_realm_ad_plugin-dev
3+
4+
# Default goal
5+
.DEFAULT_GOAL := help
6+
7+
# Phony targets
8+
.PHONY: help build default shell clean stop logs rebuild restart test
9+
10+
## Default target to build and run
11+
default: build run
12+
13+
help: ## Diplay this help
14+
@echo "Usage: make [target]"
15+
@echo "Targets:"
16+
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
17+
18+
build: ## Build from Dockerfile
19+
docker build -t $(IMAGE_NAME) .
20+
21+
rebuild: ## Build without cache
22+
docker build -t $(IMAGE_NAME) --no-cache .
23+
24+
run: ## Run in the background
25+
docker inspect $(CONTAINER_NAME) >/dev/null 2>&1 && docker rm -f $(CONTAINER_NAME) || true
26+
docker run --name=$(CONTAINER_NAME) -v $(PWD):/app -d $(IMAGE_NAME) sleep infinity
27+
28+
shell: build run ## Open a shell in the running container
29+
docker exec -it $(CONTAINER_NAME) /bin/bash
30+
31+
stop: ## Stop the running container
32+
docker stop $(CONTAINER_NAME) || true
33+
34+
restart: stop run ## Restart the container
35+
36+
clean: ## clean
37+
docker rm -f $(CONTAINER_NAME) >> /dev/null 2>&1 || true
38+
docker rmi -f $(IMAGE_NAME) >> /dev/null 2>&1 || true
39+
40+
## Use inside the container
41+
42+
local-build: ## Inside Container: Build a local gem inside the container
43+
sudo gem build
44+
#sudo gem install radcli
45+
sudo gem install smart_proxy_realm_ad_plugin-0.1.gem
46+
sudo find /var/lib -name radcli*
47+
sudo find /var -name provider.rb
48+
sudo find /var -name realm*
49+

docs/INTRO.md

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Getting Started with the [`smart_proxy_realm_ad_plugin`]
2+
3+
This tutorial will guide you through the steps to build, run, and use the [`smart_proxy_realm_ad_plugin`]
4+
5+
This container is based on Ubuntu 22.04 and includes various development tools, libraries, and configurations for working with Kerberos and LDAP.
6+
7+
## Prerequisites
8+
9+
- Docker installed on your machine.
10+
- Internet connection to pull base images and clone repositories.
11+
12+
## Step 1: Clone the Repository
13+
14+
First, clone the repository containing the Dockerfile and related scripts.
15+
16+
```sh
17+
git clone https://github.com/your-repo/smart_proxy_realm_ad_plugin.git
18+
cd smart_proxy_realm_ad_plugin
19+
```
20+
21+
## Step 2: Build the Docker Image
22+
23+
Build the Docker image using the provided Dockerfile. This step will install all necessary packages and configure the environment.
24+
25+
```sh
26+
docker build -t smart_proxy_realm_ad_plugin:master .
27+
```
28+
29+
## Step 3: Run the Docker Container
30+
31+
Run the container in the background. This command will start the container and keep it running.
32+
33+
```sh
34+
docker run --name smart_proxy_realm_ad_plugin-dev -d smart_proxy_realm_ad_plugin:master sleep infinity
35+
```
36+
37+
## Step 4: Access the Container
38+
39+
Open a shell inside the running container to start using it.
40+
41+
```sh
42+
docker exec -it smart_proxy_realm_ad_plugin-dev /bin/bash
43+
```
44+
45+
## Step 5: Verify the Environment
46+
47+
Once inside the container, you can verify that the environment is set up correctly.
48+
49+
1. **Check Installed Packages**:
50+
```sh
51+
dpkg -l | grep -E 'ruby|automake|autoconf|gcc|make|libkrb5-dev|libldap2-dev|libsasl2-dev|adcli|krb5-user|ldap-utils|dnsutils|git'
52+
```
53+
54+
2. **Check DNS Configuration**:
55+
```sh
56+
cat /etc/resolv.conf
57+
```
58+
59+
3. **Check Oh-My-Bash Installation**:
60+
```sh
61+
echo $OSH
62+
```
63+
64+
## Step 6: Run Tests (Optional)
65+
66+
If you have tests to run inside the container, you can execute them as follows:
67+
68+
```sh
69+
docker exec smart_proxy_realm_ad_plugin-dev /bin/bash -c "cd /path/to/tests && ./run_tests.sh"
70+
```
71+
72+
## Step 7: Clean Up
73+
74+
When you are done, you can stop and remove the container, and optionally remove the image.
75+
76+
1. **Stop the Container**:
77+
```sh
78+
docker stop smart_proxy_realm_ad_plugin-dev
79+
```
80+
81+
2. **Remove the Container**:
82+
```sh
83+
docker rm smart_proxy_realm_ad_plugin-dev
84+
```
85+
86+
3. **Remove the Image** (optional):
87+
```sh
88+
docker rmi smart_proxy_realm_ad_plugin:master
89+
```
90+
91+
## Summary
92+
93+
You have successfully built and run the [`smart_proxy_realm_ad_plugin`] container. You can now use this container for development and testing purposes, with all necessary tools and configurations pre-installed.

0 commit comments

Comments
 (0)