feat: Update toolbox-base and template with latest Docker configurations and documentation

\n- Updated Dockerfiles in both toolbox-base and toolbox-template
- Modified build scripts and docker-compose configurations
- Added new audit tools and documentation files
- Created new toolbox-DocStack and toolbox-QADocker implementations
- Updated README and maintenance documentation
This commit is contained in:
2025-10-31 12:46:36 -05:00
parent 48530814d5
commit ab57e3a3a1
92 changed files with 4610 additions and 190 deletions

View File

@@ -0,0 +1 @@
{"schemaVersion":2,"mediaType":"application/vnd.oci.image.index.v1+json","manifests":[{"mediaType":"application/vnd.oci.image.manifest.v1+json","digest":"sha256:b67ce052e76b308d4e0f2e7d1a9dab6b078f9b22d981f7ab36916ea34f2ff06f","size":8758,"annotations":{"org.opencontainers.image.ref.name":"latest"}}]}

View File

@@ -0,0 +1 @@
{"imageLayoutVersion":"1.0.0"}

View File

@@ -0,0 +1,25 @@
{
"name": "TSYSDevStack Docker QA Toolbox",
"dockerComposeFile": [
"../docker-compose.yml"
],
"service": "toolbox-qadocker",
"workspaceFolder": "/workspace",
"remoteUser": "toolbox",
"runServices": [
"toolbox-qadocker"
],
"overrideCommand": false,
"postCreateCommand": "zsh -lc 'echo \"Docker QA environment ready. Available tools: trivy, hadolint, docker, dockerfilelint\"'",
"mounts": [
"source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind"
],
"customizations": {
"vscode": {
"extensions": [
"ms-azuretools.vscode-docker",
"hadolint.hadolint"
]
}
}
}

View File

@@ -0,0 +1,101 @@
# 🛡️ Docker QA Toolbox Audit Checklist
This checklist ensures the Docker QA toolbox meets all security, functionality, and maintainability requirements for Docker image auditing.
## 🔒 Security Audit
- [ ] All packages installed with specific versions (no `latest` tags)
- [ ] All external downloads verified with checksums/signatures
- [ ] No root access possible at runtime (sudo removed)
- [ ] Non-root user properly configured with UID/GID mapping
- [ ] No hardcoded secrets or credentials in image
- [ ] Minimal attack surface (unnecessary packages removed)
- [ ] Regular security scanning implemented (Trivy integration)
- [ ] Base image (Ubuntu) regularly updated
- [ ] All aqua packages verified through registry
- [ ] Docker socket access properly secured
## 🛠️ Functionality Audit
- [ ] All Docker QA tools properly installed and accessible
- [ ] All tools respond to `--version` flag correctly
- [ ] Aqua proxy mechanism properly configured
- [ ] Docker access to host daemon working correctly
- [ ] Security scanning tools (Trivy, Hadolint) functional
- [ ] Dockerfile linting tools working properly
- [ ] Shell configurations properly set up (zsh, bash)
- [ ] Environment variables properly configured
- [ ] PATH correctly set for all tools
- [ ] User home directory properly configured
- [ ] Workspace directory properly set up with correct permissions
## 🏗️ Build Process Audit
- [ ] Dockerfile follows best practices
- [ ] Multi-stage build optimizations implemented
- [ ] Build cache properly utilized
- [ ] Build arguments properly validated
- [ ] Error handling in build scripts comprehensive
- [ ] Build verification tests implemented
- [ ] Image tagging strategy consistent
- [ ] Release process properly documented
## 🧪 Testing Audit
- [ ] Automated testing of all installed tools
- [ ] Integration tests for Docker daemon access
- [ ] Regression tests for known issues
- [ ] Security scanning of built images
- [ ] Performance benchmarks
- [ ] Security scanning during build
## 📚 Documentation Audit
- [ ] README.md accurately reflects current state
- [ ] All tools properly documented
- [ ] Usage examples for Docker QA workflows provided
- [ ] Troubleshooting guide included
- [ ] Contribution guidelines clear
- [ ] License information up to date
## 🔄 Maintenance Audit
- [ ] Dependency update strategy defined
- [ ] Version pinning strategy consistent
- [ ] Backward compatibility maintained
- [ ] Deprecation policy established
- [ ] Release notes properly maintained
- [ ] Issue tracking process defined
## 🎯 Specialized QA Features Audit
- [ ] Trivy vulnerability scanning functional
- [ ] Hadolint Dockerfile linting operational
- [ ] Dockerfilelint working correctly
- [ ] Docker history/inspect tools accessible
- [ ] Image layer analysis capabilities present
- [ ] Best practices validation tools available
## 📈 Performance Audit
- [ ] Image size optimized
- [ ] Startup time acceptable
- [ ] Memory footprint reasonable
- [ ] CPU usage within expected bounds
- [ ] Docker scanning performance adequate
## 🌐 Compatibility Audit
- [ ] Works on all supported platforms
- [ ] Docker daemon access functional across platforms
- [ ] Backward compatibility with Docker versions maintained
- [ ] Integration with common CI/CD tools verified
## 🧹 Cleanup Audit
- [ ] Temporary files properly removed
- [ ] Build artifacts cleaned up
- [ ] Cache directories properly managed
- [ ] Log files rotated or removed
- [ ] Orphaned processes prevented
- [ ] Resource leaks eliminated

View File

@@ -0,0 +1,195 @@
# Multi-stage approach to minimize final image size and attack surface
FROM ubuntu:24.04 AS installer
ARG USER_ID=1000
ARG GROUP_ID=1000
ARG USERNAME=toolbox
ARG TEA_VERSION=0.11.1
ENV DEBIAN_FRONTEND=noninteractive
# ROOT STAGE 1: System package installation for Docker QA tools only
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt/lists,sharing=locked \
apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates \
curl \
git \
jq \
bc \
locales \
openssh-client \
zsh \
unzip \
zip \
python3 \
python3-pip \
wget \
# Docker and container tools \
docker.io \
# Security scanning tools \
clamav \
# Static analysis tools \
shellcheck \
# JSON/YAML tools \
yq \
# Development tools for custom scripts \
make \
gcc \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# ROOT: Configure locale
RUN locale-gen en_US.UTF-8
ENV LANG=en_US.UTF-8 \
LANGUAGE=en_US:en \
LC_ALL=en_US.UTF-8
# ROOT: Create non-root user with matching UID/GID for host mapping
RUN if getent passwd "${USER_ID}" >/dev/null; then \
existing_user="$(getent passwd "${USER_ID}" | cut -d: -f1)"; \
userdel --remove "${existing_user}"; \
fi \
&& if ! getent group "${GROUP_ID}" >/dev/null; then \
groupadd --gid "${GROUP_ID}" "${USERNAME}"; \
fi \
&& useradd --uid "${USER_ID}" --gid "${GROUP_ID}" --shell /usr/bin/zsh --create-home "${USERNAME}"
# ROOT: Set up toolbox user home directory with proper permissions
RUN chown -R "${USER_ID}:${GROUP_ID}" "/home/${USERNAME}"
# SWITCH TO NON-ROOT USER: All further operations as toolbox user
USER ${USERNAME}
WORKDIR /home/${USERNAME}
# NON-ROOT: Install mise runtime manager for toolbox user
RUN curl -sSfL https://mise.jdx.dev/install.sh | sh
# NON-ROOT: Update PATH for mise tools
ENV PATH=/home/${USERNAME}/.local/bin:/home/${USERNAME}/.local/share/mise/shims:$PATH
# NON-ROOT: Install Node.js via mise as toolbox user
RUN mise install node@22.13.0 && mise use -g node@22.13.0
# NON-ROOT: Install aqua package manager for toolbox user
RUN curl -sSfL https://raw.githubusercontent.com/aquaproj/aqua-installer/v2.3.1/aqua-installer > /tmp/aqua-installer.sh && \
chmod +x /tmp/aqua-installer.sh && \
AQUA_ROOT_DIR=/home/${USERNAME}/.local/share/aquaproj-aqua /tmp/aqua-installer.sh && \
rm /tmp/aqua-installer.sh
# NON-ROOT: Update PATH for aqua tools
ENV PATH=/home/${USERNAME}/.local/share/aquaproj-aqua/bin:$PATH
# NON-ROOT: Install Oh My Zsh
RUN git clone --depth=1 https://github.com/ohmyzsh/ohmyzsh.git ~/.oh-my-zsh
# NON-ROOT: Configure shells (zsh, bash) with all customizations
RUN cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc \
&& sed -i "s/^plugins=(git)$/plugins=(git docker docker-compose)/" ~/.zshrc \
&& printf "\nexport PATH=\"\$HOME/.local/share/aquaproj-aqua/bin:\$HOME/.local/share/mise/shims:\$HOME/.local/bin:\$PATH\"\n" >> ~/.zshrc \
&& printf "\n# Starship prompt\neval \"\$(starship init zsh)\"\n" >> ~/.zshrc \
&& printf "\n# mise runtime manager\neval \"\$(mise activate zsh)\"\n" >> ~/.zshrc \
&& printf "\n# direnv\nexport DIRENV_LOG_FORMAT=\"\"\neval \"\$(direnv hook zsh)\"\n" >> ~/.zshrc \
&& printf "\nexport AQUA_GLOBAL_CONFIG=\"\$HOME/.config/aquaproj-aqua/aqua.yaml\"\n" >> ~/.bashrc \
&& printf "\n# mise runtime manager (bash)\neval \"\$(mise activate bash)\"\n" >> ~/.bashrc \
&& printf "\n# direnv\nexport DIRENV_LOG_FORMAT=\"\"\neval \"\$(direnv hook bash)\"\n" >> ~/.bashrc
# NON-ROOT: Install aqua packages for Docker QA tools
RUN mkdir -p ~/.config/aquaproj-aqua \
&& echo "version: 1.0.0\nregistries:\n - type: standard\n ref: v4.431.0\npackages:\n - name: aquasecurity/trivy@v0.54.1\n - name: hadolint/hadolint@v2.14.0\n - name: github/gh@v2.69.0\n - name: dandavison/delta@0.18.2\n - name: ajeetdsouza/zoxide@v0.9.8\n - name: mikefarah/yq@v4.48.1\n - name: direnv/direnv@v2.37.1" > ~/.config/aquaproj-aqua/aqua.yaml \
&& aqua install \
&& aqua install --all
# NON-ROOT: Install additional Docker QA tools via npm
RUN mise exec -- npm install -g dockerfilelint@latest && mise reshim
# NON-ROOT: Install additional Python-based tools using --break-system-packages
RUN pip3 install --break-system-packages docker-image-py
# ROOT: Set up workspace directory
USER root
RUN mkdir -p /workspace && chown "${USER_ID}:${GROUP_ID}" /workspace
USER ${USERNAME}
# NON-ROOT: Verify all tools are accessible during build
RUN bash -c 'command -v docker && command -v dockerfilelint' \
&& bash -c 'docker --version && node --version && npm --version'
# NON-ROOT: Final mise reshim to ensure all tools are properly linked
RUN mise reshim
# FINAL STAGE: Copy completed setup to minimize image and enhance security
FROM ubuntu:24.04
ARG USER_ID=1000
ARG GROUP_ID=1000
ARG USERNAME=toolbox
ARG TEA_VERSION=0.11.1
ENV DEBIAN_FRONTEND=noninteractive
# ROOT: Install minimal runtime dependencies only
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt/lists,sharing=locked \
apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates \
curl \
git \
jq \
bc \
locales \
openssh-client \
zsh \
unzip \
zip \
python3 \
docker.io \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# ROOT: Restore system-wide configurations
RUN locale-gen en_US.UTF-8
ENV LANG=en_US.UTF-8 \
LANGUAGE=en_US:en \
LC_ALL=en_US.UTF-8
# ROOT: Create non-root user with matching UID/GID for host mapping
RUN if getent passwd "${USER_ID}" >/dev/null; then \
existing_user="$(getent passwd "${USER_ID}" | cut -d: -f1)"; \
userdel --remove "${existing_user}"; \
fi \
&& if ! getent group "${GROUP_ID}" >/dev/null; then \
groupadd --gid "${GROUP_ID}" "${USERNAME}"; \
fi \
&& useradd --uid "${USER_ID}" --gid "${GROUP_ID}" --shell /usr/bin/zsh --create-home "${USERNAME}"
# ROOT: Copy the complete user environment from the installer stage
COPY --from=installer --chown=${USER_ID}:${GROUP_ID} /home/${USERNAME} /home/${USERNAME}
# ROOT: Create workspace directory
RUN mkdir -p /workspace && chown "${USER_ID}:${GROUP_ID}" /workspace
# ROOT: Install system-wide tools (tea and starship) which were in the source image
RUN curl -fsSL "https://dl.gitea.io/tea/${TEA_VERSION}/tea-${TEA_VERSION}-linux-amd64" -o /tmp/tea \
&& curl -fsSL "https://dl.gitea.io/tea/${TEA_VERSION}/tea-${TEA_VERSION}-linux-amd64.sha256" -o /tmp/tea.sha256 \
&& sed -n 's/ .*//p' /tmp/tea.sha256 | awk '{print $1 " /tmp/tea"}' | sha256sum -c - \
&& install -m 0755 /tmp/tea /usr/local/bin/tea \
&& rm -f /tmp/tea /tmp/tea.sha256
RUN curl -fsSL https://starship.rs/install.sh | sh -s -- -y -b /usr/local/bin
# ROOT: Security hardening - remove sudo if present
RUN apt-get remove -y sudo 2>/dev/null || true && apt-get autoremove -y 2>/dev/null || true && rm -rf /var/lib/apt/lists/* 2>/dev/null || true
# ROOT: Final environment variables
ENV PATH=/home/${USERNAME}/.local/share/aquaproj-aqua/bin:/home/${USERNAME}/.local/share/mise/shims:/home/${USERNAME}/.local/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin
ENV SHELL=/usr/bin/zsh \
AQUA_GLOBAL_CONFIG=/home/${USERNAME}/.config/aquaproj-aqua/aqua.yaml
# FINAL USER: Switch to toolbox user for runtime
USER ${USERNAME}
WORKDIR /workspace
CMD ["/usr/bin/zsh"]

View File

@@ -0,0 +1,34 @@
# Docker QA Toolbox Prompt
You are an AI assistant working inside the Docker QA Toolbox container. Your purpose is to assist with Docker image auditing, security scanning, and quality assurance.
## Your Environment
- You're running as the 'toolbox' user with the same UID/GID as the host user
- You have access to the Docker daemon via the mounted socket
- You're in a bash shell with access to various Docker auditing tools
## Your Capabilities
1. Scan Docker images for vulnerabilities using Trivy
2. Lint Dockerfiles using Hadolint and dockerfilelint
3. Analyze Docker image layers and composition
4. Validate Docker best practices
5. Perform security audits of container images
6. Generate reports on Docker image quality
## Common Commands
- `trivy image <image-name>` - Scan an image for vulnerabilities
- `hadolint <Dockerfile>` - Lint a Dockerfile against best practices
- `dockerfilelint <Dockerfile>` - Additional Dockerfile linting
- `docker history <image-name>` - Show image layer history
- `docker inspect <image-name>` - Show image metadata
- `docker run --rm -it <image-name> /bin/sh` - Inspect image contents interactively
## Best Practices to Follow
1. Always scan images before deploying to production
2. Use multi-stage builds to minimize attack surface
3. Run containers as non-root users
4. Pin base image versions rather than using 'latest'
5. Regularly update base images and packages
6. Verify checksums when downloading external binaries
Remember: The workspace directory is mounted from your host system, so you can analyze Dockerfiles and images from the host.

View File

@@ -0,0 +1,85 @@
# 🛡️ Docker QA Toolbox
A specialized development environment for Docker image auditing, security scanning, and quality assurance.
## 🚀 Quick Start
```bash
cd output/toolbox-QADocker
./build.sh # build the image with UID/GID matching your host
./run.sh up # launch the toolbox-qadocker service in the background
docker exec -it tsysdevstack-toolboxstack-toolbox-qadocker zsh
```
Use `./run.sh down` to stop the container when you are finished.
## 🧰 Included Tools
### Security Scanning
- **Trivy** - Comprehensive vulnerability scanner for containers and code
- **ClamAV** - Antivirus scanner for file system analysis
- **Hadolint** - Dockerfile linter for best practices
### Docker Analysis
- **Dockerfilelint** - Node.js-based Dockerfile linter
- **Docker** - Docker CLI with access to host Docker daemon via socket
- **Docker Buildx** - Docker CLI plugin for extended build capabilities
### Development Tools
- **Git** - Version control system
- **Zsh** - Interactive shell with Oh My Zsh framework
- **Mise** - Runtime manager for language versions
- **Aqua** - CLI tool manager
- **YQ** - YAML/JSON processor
- **JQ** - JSON processor
## 📋 QA Workflows
### Security Scanning
```bash
# Scan a Docker image with Trivy
trivy image <your-image-name>
# Scan a Dockerfile with Hadolint
hadolint Dockerfile
# Scan a Dockerfile with dockerfilelint
dockerfilelint Dockerfile
```
### Image Analysis
```bash
# Analyze image layers and size
docker history <your-image-name>
# Extract image contents for analysis
docker save <your-image-name> -o image.tar
tar -xf image.tar
```
### Best Practices Validation
The toolbox includes tools to validate Docker best practices:
- Hadolint for Dockerfile best practices
- Trivy for security vulnerabilities
- Docker's own best practices recommendations
## ⚙️ Configuration
The toolbox is configured to:
- Run as a non-root user with host UID/GID mapping
- Access the host Docker daemon via socket mounting
- Include both Docker build and runtime analysis tools
- Follow security best practices (no sudo, minimal attack surface)
## 🔐 Security Features
- Non-root user execution with UID/GID mapping
- Sudo is removed from the final image
- Multi-stage build minimizing attack surface
- Regular security scanning capabilities
## 🤖 AI Agent
This toolbox is maintained by **ToolboxBot**, an AI agent focused on Docker QA tooling.
## 📄 License
See [LICENSE](../LICENSE) for full terms.

View File

@@ -0,0 +1,26 @@
# Docker QA Toolbox SEED
## Purpose
This toolbox is specifically designed for Docker image auditing, security scanning, and quality assurance. It provides a comprehensive set of tools to analyze, validate, and secure Docker images and Dockerfiles.
## Core Functionality
- Security scanning of Docker images using Trivy
- Linting of Dockerfiles using Hadolint and dockerfilelint
- Analysis of Docker image composition and layers
- Validation of Docker best practices
- Compliance checking against security standards
## Target Use Cases
- Pre-deployment security scanning of Docker images
- Dockerfile quality validation in CI/CD pipelines
- Docker image composition analysis
- Security audit of existing container images
- Verification of container best practices
## Key Tools
- Trivy: Comprehensive vulnerability scanner
- Hadolint: Dockerfile linter for best practices
- Dockerfilelint: Additional Dockerfile validation
- Docker CLI: Direct access to Docker daemon
- Mise: Runtime version management
- Aqua: CLI tool management

View File

@@ -0,0 +1,22 @@
version: 1.0.0
registries:
- type: standard
ref: v4.431.0
packages:
# Docker and container analysis tools
- name: aquasecurity/trivy@v0.54.1
- name: hadolint/hadolint@v2.14.0
# GitHub and collaboration tools
- name: cli/cli@v2.82.1
# Environment and runtime management
- name: direnv/direnv@v2.37.1
- name: dandavison/delta@0.18.2
- name: ajeetdsouza/zoxide@v0.9.8
# Development and build tools
- name: mikefarah/yq@v4.48.0
# Configuration management
- name: twpayne/chezmoi@v2.66.1

View File

@@ -0,0 +1,198 @@
#!/usr/bin/env bash
set -euo pipefail
# Security: Validate input parameters to prevent command injection
sanitized_input() {
local input="$1"
# Check for potentially dangerous characters/commands
case "$input" in
*[\;\|\&\`\$]*)
echo "Error: Invalid input detected: $input" >&2
exit 1
;;
esac
}
# Validate dependencies
if ! command -v docker &> /dev/null; then
echo "Error: docker is required but not installed." >&2
exit 1
fi
if ! docker buildx version &> /dev/null; then
echo "Error: docker buildx is required but not available." >&2
exit 1
fi
IMAGE_NAME="tsysdevstack-toolboxstack-toolbox-qadocker"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Sanitize user input
USER_ID="${USER_ID_OVERRIDE:-$(id -u)}"
sanitized_input "$USER_ID"
GROUP_ID="${GROUP_ID_OVERRIDE:-$(id -g)}"
sanitized_input "$GROUP_ID"
USERNAME="${USERNAME_OVERRIDE:-toolbox}"
sanitized_input "$USERNAME"
TEA_VERSION="${TEA_VERSION_OVERRIDE:-0.11.1}"
sanitized_input "$TEA_VERSION"
BUILDER_NAME="${BUILDER_NAME:-tsysdevstack-builder}"
sanitized_input "$BUILDER_NAME"
CACHE_DIR="${SCRIPT_DIR}/.build-cache"
TAG="${TAG_OVERRIDE:-dev}"
sanitized_input "$TAG"
RELEASE_TAG="${RELEASE_TAG_OVERRIDE:-release-current}"
sanitized_input "$RELEASE_TAG"
VERSION_TAG="${VERSION_TAG_OVERRIDE:-}"
if [[ -n "$VERSION_TAG" ]]; then
sanitized_input "$VERSION_TAG"
fi
PUSH="${PUSH_OVERRIDE:-false}"
echo "Building ${IMAGE_NAME} with UID=${USER_ID} GID=${GROUP_ID} USERNAME=${USERNAME}"
echo "Primary tag: ${TAG}"
# Ensure builder exists
if ! docker buildx inspect "${BUILDER_NAME}" >/dev/null 2>&1; then
echo "Creating builder: ${BUILDER_NAME}"
if ! docker buildx create --driver docker-container --name "${BUILDER_NAME}" --use >/dev/null; then
echo "Error: Failed to create Docker buildx builder." >&2
exit 1
fi
else
echo "Using existing builder: ${BUILDER_NAME}"
if ! docker buildx use "${BUILDER_NAME}" >/dev/null; then
echo "Error: Failed to use Docker buildx builder." >&2
exit 1
fi
fi
# Ensure cache directory exists
if ! mkdir -p "${CACHE_DIR}"; then
echo "Error: Failed to create cache directory: ${CACHE_DIR}" >&2
exit 1
fi
echo "Starting build..."
BUILD_OUTPUT=$(mktemp)
trap 'rm -f "$BUILD_OUTPUT"' EXIT
# Build the image
if ! docker buildx build \
--builder "${BUILDER_NAME}" \
--load \
--progress=plain \
--build-arg USER_ID="${USER_ID}" \
--build-arg GROUP_ID="${GROUP_ID}" \
--build-arg USERNAME="${USERNAME}" \
--build-arg TEA_VERSION="${TEA_VERSION}" \
--cache-from "type=local,src=${CACHE_DIR}" \
--cache-to "type=local,dest=${CACHE_DIR},mode=max" \
--tag "${IMAGE_NAME}:${TAG}" \
"${SCRIPT_DIR}" 2>&1 | tee "${BUILD_OUTPUT}"; then
echo "Error: Docker build failed. Check output above for details." >&2
exit 1
fi
echo "Build completed successfully."
# Run comprehensive verification tests
echo "Running comprehensive verification tests..."
if ! docker run --rm "${IMAGE_NAME}:${TAG}" zsh -c 'echo "Container starts successfully as $(whoami) user"'; then
echo "Error: Failed to start container with basic test." >&2
exit 1
fi
# Verify core tools are available to toolbox user
echo "Verifying core tools for toolbox user..."
CORE_TOOLS=("zsh" "git" "curl" "jq" "docker" "trivy" "hadolint")
for tool in "${CORE_TOOLS[@]}"; do
if ! docker run --rm "${IMAGE_NAME}:${TAG}" su - toolbox -c "which $tool" >/dev/null 2>&1; then
echo "Error: Core tool '$tool' not found in PATH for toolbox user." >&2
exit 1
fi
done
# Verify Docker QA tools are available to toolbox user
echo "Verifying Docker QA tools for toolbox user..."
QA_TOOLS=("dockerfilelint" "yq")
for tool in "${QA_TOOLS[@]}"; do
if ! docker run --rm "${IMAGE_NAME}:${TAG}" su - toolbox -c "which $tool" >/dev/null 2>&1; then
echo "Error: QA tool '$tool' not found in PATH for toolbox user." >&2
exit 1
fi
done
# Verify Node.js and npm are working properly
echo "Verifying Node.js runtime..."
if ! docker run --rm "${IMAGE_NAME}:${TAG}" su - toolbox -c "node --version && npm --version" >/dev/null 2>&1; then
echo "Error: Node.js or npm not working properly for toolbox user." >&2
exit 1
fi
# Verify mise is managing tools properly
echo "Verifying mise runtime management..."
if ! docker run --rm "${IMAGE_NAME}:${TAG}" su - toolbox -c "mise --version" >/dev/null 2>&1; then
echo "Error: Mise not available for toolbox user." >&2
exit 1
fi
# Verify aqua is managing tools properly
echo "Verifying aqua package management..."
if ! docker run --rm "${IMAGE_NAME}:${TAG}" su - toolbox -c "aqua --version" >/dev/null 2>&1; then
echo "Error: Aqua not available for toolbox user." >&2
exit 1
fi
# Final security check: verify container runs as toolbox user
echo "Verifying runtime security model..."
RUNTIME_USER=$(docker run --rm "${IMAGE_NAME}:${TAG}" whoami)
if [ "$RUNTIME_USER" != "toolbox" ]; then
echo "Error: Container is not running as toolbox user. Current user: $RUNTIME_USER" >&2
exit 1
fi
echo "All verifications passed. Security model is correct."
if [[ "${PUSH}" == "true" ]]; then
echo "Pushing ${IMAGE_NAME}:${TAG}"
if ! docker push "${IMAGE_NAME}:${TAG}"; then
echo "Error: Failed to push ${IMAGE_NAME}:${TAG}" >&2
exit 1
fi
if [[ "${TAG}" == "dev" && -n "${VERSION_TAG}" ]]; then
if ! docker tag "${IMAGE_NAME}:${TAG}" "${IMAGE_NAME}:${VERSION_TAG}"; then
echo "Error: Failed to tag ${IMAGE_NAME}:${VERSION_TAG}" >&2
exit 1
fi
echo "Pushing ${IMAGE_NAME}:${VERSION_TAG}"
if ! docker push "${IMAGE_NAME}:${VERSION_TAG}"; then
echo "Error: Failed to push ${IMAGE_NAME}:${VERSION_TAG}" >&2
exit 1
fi
fi
if [[ "${TAG}" == "dev" ]]; then
if ! docker tag "${IMAGE_NAME}:${TAG}" "${IMAGE_NAME}:${RELEASE_TAG}"; then
echo "Error: Failed to tag ${IMAGE_NAME}:${RELEASE_TAG}" >&2
exit 1
fi
echo "Pushing ${IMAGE_NAME}:${RELEASE_TAG}"
if ! docker push "${IMAGE_NAME}:${RELEASE_TAG}"; then
echo "Error: Failed to push ${IMAGE_NAME}:${RELEASE_TAG}" >&2
exit 1
fi
fi
fi
# Run security scan if TRIVY is available
if command -v trivy &> /dev/null; then
echo "Running security scan with Trivy..."
trivy image --exit-code 0 --severity HIGH,CRITICAL "${IMAGE_NAME}:${TAG}"
else
echo "Trivy not found. Install Trivy to perform security scanning."
fi
echo "Build process completed successfully with all verifications and security checks."

View File

@@ -0,0 +1,23 @@
services:
toolbox-qadocker:
container_name: tsysdevstack-toolboxstack-toolbox-qadocker
image: ${TOOLBOX_IMAGE:-tsysdevstack-toolboxstack-toolbox-qadocker:release-current}
build:
context: .
args:
USER_ID: ${LOCAL_UID:-1000}
GROUP_ID: ${LOCAL_GID:-1000}
USERNAME: ${LOCAL_USERNAME:-toolbox}
user: "${LOCAL_UID:-1000}:${LOCAL_GID:-1000}"
working_dir: /workspace
command: ["sleep", "infinity"]
init: true
tty: true
stdin_open: true
volumes:
- .:/workspace:rw
- /var/run/docker.sock:/var/run/docker.sock:rw
- ${HOME}/.local/share/mise:/home/toolbox/.local/share/mise:rw
- ${HOME}/.cache/mise:/home/toolbox/.cache/mise:rw
# Aqua configuration
- ${HOME}/.config/aquaproj-aqua:/home/toolbox/.config/aquaproj-aqua:rw

View File

@@ -0,0 +1,35 @@
#!/usr/bin/env bash
set -euo pipefail
# Validate input parameters
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <version-tag>"
exit 1
fi
VERSION="$1"
IMAGE_NAME="tsysdevstack-toolboxstack-toolbox-qadocker"
# Build the image with the version tag
echo "Building ${IMAGE_NAME}:${VERSION}"
if ! docker build --tag "${IMAGE_NAME}:${VERSION}" .; then
echo "Error: Failed to build ${IMAGE_NAME}:${VERSION}" >&2
exit 1
fi
# Run tests
echo "Running tests..."
if ! ./test.sh; then
echo "Error: Tests failed for ${IMAGE_NAME}:${VERSION}" >&2
exit 1
fi
# Create release tag
echo "Creating release tag..."
if ! docker tag "${IMAGE_NAME}:${VERSION}" "${IMAGE_NAME}:release-current"; then
echo "Error: Failed to create release tag for ${IMAGE_NAME}" >&2
exit 1
fi
echo "Release ${IMAGE_NAME}:${VERSION} completed successfully!"

View File

@@ -0,0 +1,69 @@
#!/usr/bin/env bash
set -euo pipefail
# Security: Validate input parameters to prevent command injection
sanitized_input() {
local input="$1"
# Check for potentially dangerous characters/commands
case "$input" in
*[\;\|\&\`\$]*)
echo "Error: Invalid input detected: $input" >&2
exit 1
;;
esac
}
# Validate dependencies
if ! command -v docker &> /dev/null; then
echo "Error: docker is required but not installed." >&2
exit 1
fi
if ! command -v docker compose &> /dev/null; then
echo "Error: docker compose is required but not installed." >&2
exit 1
fi
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
COMPOSE_FILE="${SCRIPT_DIR}/docker-compose.yml"
# Sanitize user input
export LOCAL_UID="${USER_ID_OVERRIDE:-$(id -u)}"
sanitized_input "$LOCAL_UID"
export LOCAL_GID="${GROUP_ID_OVERRIDE:-$(id -g)}"
sanitized_input "$LOCAL_GID"
export LOCAL_USERNAME="${USERNAME_OVERRIDE:-toolbox}"
sanitized_input "$LOCAL_USERNAME"
export TOOLBOX_IMAGE="${TOOLBOX_IMAGE_OVERRIDE:-tsysdevstack-toolboxstack-toolbox-qadocker:release-current}"
sanitized_input "$TOOLBOX_IMAGE"
if [[ ! -f "${COMPOSE_FILE}" ]]; then
echo "Error: docker-compose.yml not found at ${COMPOSE_FILE}" >&2
exit 1
fi
ACTION="${1:-up}"
sanitized_input "$ACTION"
shift || true
if [[ "${ACTION}" == "up" ]]; then
# Create necessary directories for the toolbox tools with proper permissions
mkdir -p "${HOME}/.local/share/mise" "${HOME}/.cache/mise"
mkdir -p "${HOME}/.config/aquaproj-aqua"
fi
case "${ACTION}" in
up)
docker compose -f "${COMPOSE_FILE}" up --build --detach "$@"
echo "Container started. Use 'docker exec -it tsysdevstack-toolboxstack-toolbox-qadocker zsh' to access the shell."
;;
down)
docker compose -f "${COMPOSE_FILE}" down "$@"
echo "Container stopped."
;;
*)
echo "Usage: $0 [up|down] [additional docker compose args]" >&2
exit 1
;;
esac

View File

@@ -0,0 +1,42 @@
#!/usr/bin/env bash
set -euo pipefail
echo "Running security audit on the current environment..."
# Check for any security issues with the current setup
echo "Checking for common security issues..."
# Check if running as root (should not be)
if [ "$EUID" -eq 0 ]; then
echo "WARNING: Running as root user" >&2
exit 1
else
echo "✓ Running as non-root user"
fi
# Check for sudo access (should not have)
if command -v sudo &> /dev/null; then
echo "WARNING: Sudo is available in the container" >&2
exit 1
else
echo "✓ Sudo correctly removed from container"
fi
# Verify important security tools are available
echo "Checking for security tools..."
if command -v trivy &> /dev/null; then
echo "✓ Trivy security scanner available"
else
echo "✗ Trivy security scanner not available" >&2
exit 1
fi
if command -v hadolint &> /dev/null; then
echo "✓ Hadolint Dockerfile linter available"
else
echo "✗ Hadolint Dockerfile linter not available" >&2
exit 1
fi
echo "Security audit completed successfully!"

View File

@@ -0,0 +1,41 @@
#!/usr/bin/env bash
set -euo pipefail
echo "Testing toolbox-QADocker functionality..."
# Test core tools availability
echo "Testing core tools..."
if ! command -v zsh &> /dev/null; then
echo "Error: zsh is not available" >&2
exit 1
fi
if ! command -v git &> /dev/null; then
echo "Error: git is not available" >&2
exit 1
fi
if ! command -v docker &> /dev/null; then
echo "Error: docker is not available" >&2
exit 1
fi
# Test QA tools availability
echo "Testing QA tools..."
if ! command -v trivy &> /dev/null; then
echo "Error: trivy is not available" >&2
exit 1
fi
if ! command -v hadolint &> /dev/null; then
echo "Error: hadolint is not available" >&2
exit 1
fi
if ! command -v dockerfilelint &> /dev/null; then
echo "Error: dockerfilelint is not available" >&2
exit 1
fi
echo "All tests passed! toolbox-QADocker is functional."