1+ # syntax=docker/dockerfile:1.8
2+ # check=error=true
3+ #
4+ # HARDENED TRG DevContainer Dockerfile
5+ # This Dockerfile creates a security-hardened development environment for Web3 security research
6+ # with enhanced security features, capability dropping, and minimal attack surface.
7+ #
8+ # Key security features:
9+ # - Multi-stage build for Echidna binary
10+ # - Non-root user execution
11+ # - Minimal package installation
12+ # - Security-hardened toolchain
13+ # - Reduced tool set for security focus
14+
15+ # # Multi-stage build for Echidna
16+ # Pull latest prebuilt Echidna binary from Crytic's official image
17+ # Echidna is a fuzzing tool for Ethereum smart contracts
18+ FROM --platform=linux/amd64 ghcr.io/crytic/echidna/echidna:latest AS echidna
19+
20+ # Base image: Latest Debian with VS Code DevContainer support
21+ # This provides a stable, security-focused base for development
22+ FROM mcr.microsoft.com/devcontainers/base:bookworm
23+
24+ # Install essential system packages for development
25+ # These are the minimal packages needed for Web3 development tools
26+ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
27+ bash-completion # Shell completion support \
28+ build-essential # Compilation tools (gcc, make, etc.) \
29+ curl # HTTP client for downloading tools \
30+ git # Version control system \
31+ jq # JSON processor for tool outputs \
32+ pkg-config # Package configuration helper \
33+ sudo # Privilege escalation (needed for some tools) \
34+ unzip # Archive extraction \
35+ vim # Text editor \
36+ wget # Alternative HTTP client \
37+ zsh # Advanced shell \
38+ && rm -rf /var/lib/apt/lists/*
39+
40+
41+
42+ # Install Python development dependencies
43+ # Required for Python-based security tools and package management
44+ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
45+ python3-pip # Python package installer \
46+ libpython3-dev # Python development headers \
47+ python3-dev # Python development tools \
48+ python3-venv # Python virtual environment support \
49+ && rm -rf /var/lib/apt/lists/*
50+
51+ # Switch to vscode user for security (drop privileges)
52+ # This ensures all subsequent operations run as non-root user
53+ USER vscode
54+ WORKDIR /home/vscode
55+ ENV HOME=/home/vscode
56+
57+ # Install uv
58+ RUN curl -LsSf https://astral.sh/uv/install.sh | sh
59+
60+ # Update PATH environment for tool access
61+ # Configure paths for Python, Node.js, and other tools
62+ ENV UV_LOCAL_BIN=$HOME/.cargo/bin
63+ ENV USR_LOCAL_BIN=/usr/local/bin
64+ ENV LOCAL_BIN=${HOME}/.local/bin
65+ ENV PNPM_HOME=${HOME}/.local/share/pnpm
66+ ENV PATH=${PATH}:${USR_LOCAL_BIN}:${LOCAL_BIN}:${PNPM_HOME}:${UV_LOCAL_BIN}
67+
68+ # Install Python 3.12 with uv
69+ RUN uv python install 3.12
70+
71+ # Set the default shell execution for subsequent RUN commands
72+ # Use zsh for better shell features and compatibility
73+ ENV SHELL=/usr/bin/zsh
74+ SHELL ["/bin/zsh" , "-ic" ]
75+
76+ # Install Rust programming language
77+ # Required for various Web3 security tools and Foundry framework
78+ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
79+ ENV PATH="$HOME/.cargo/bin:$PATH"
80+
81+ # Install Go programming language through asdf version manager
82+ # asdf provides consistent version management across different tools
83+ # Set asdf manager version for reproducibility
84+ RUN git clone https://github.com/asdf-vm/asdf.git $HOME/.asdf --branch v0.15.0 && \
85+ echo '. $HOME/.asdf/asdf.sh' >> $HOME/.zshrc && \
86+ echo 'fpath=(${ASDF_DIR}/completions $fpath)' >> $HOME/.zshrc && \
87+ echo 'autoload -Uz compinit && compinit' >> $HOME/.zshrc && \
88+ . $HOME/.asdf/asdf.sh && \
89+ asdf plugin add golang && \
90+ asdf install golang latest && \
91+ asdf global golang latest
92+
93+ # Switch to root user temporarily for Node.js installation
94+ # Some tools require root access for system-wide installation
95+ USER root
96+
97+ # Install Node.js, npm, yarn, and pnpm through devcontainer features
98+ # These are essential for JavaScript/TypeScript Web3 development
99+ RUN curl -o- https://raw.githubusercontent.com/devcontainers/features/main/src/node/install.sh | bash
100+ RUN chown -R vscode:vscode ${HOME}/.npm
101+
102+ # Switch back to vscode user for security
103+ USER vscode
104+ ENV PNPM_HOME=${HOME}/.local/share/pnpm
105+ ENV PATH=${PATH}:${PNPM_HOME}
106+
107+ # Install Foundry framework for Ethereum development
108+ # Foundry provides Forge (testing), Cast (interaction), and Anvil (local blockchain)
109+ RUN curl -fsSL https://foundry.paradigm.xyz | zsh && \
110+ echo 'export PATH="$HOME/.foundry/bin:$PATH"' >> ~/.zshrc && \
111+ export PATH="$HOME/.foundry/bin:$PATH" && \
112+ ~/.foundry/bin/foundryup
113+
114+ # Install Hardhat globally for Ethereum development framework
115+ # Hardhat is a popular development environment for Ethereum
116+ RUN pnpm install hardhat -g
117+
118+ # Build and install Medusa fuzzing tool
119+ # Medusa is a fuzzing tool for smart contracts, similar to Echidna
120+ WORKDIR $HOME/medusa
121+ RUN git clone https://github.com/crytic/medusa $HOME/medusa && \
122+ export LATEST_TAG="$(git describe --tags | sed 's/-[0-9]+-gw+$//')" && \
123+ git checkout "$LATEST_TAG" && \
124+ go build -trimpath -o=$HOME/.local/bin/medusa -ldflags="-s -w" && \
125+ chmod 755 $HOME/.local/bin/medusa
126+
127+ # Return to home directory and clean up build artifacts
128+ WORKDIR $HOME
129+ RUN rm -rf medusa/
130+
131+ # Install Python-based security analysis tools (reduced set for security focus)
132+ # These tools provide essential smart contract security analysis
133+ # Focused on core tools: slither, mythril, crytic-compile, halmos, solc-select
134+ RUN uv tool install slither-analyzer && \
135+ uv tool install crytic-compile && \
136+ uv tool install slither-lsp && \
137+ uv tool install mythril && \
138+ uv tool install halmos && \
139+ uv tool install solc-select && \
140+ solc-select install 0.4.26 0.5.17 0.6.12 0.7.6 0.8.10 latest && solc-select use latest
141+
142+ # Copy Echidna binary from echidna stage to final image
143+ # This provides the prebuilt Echidna tool without rebuilding
144+ USER root
145+ COPY --from=echidna /usr/local/bin/echidna /usr/local/bin/echidna
146+ RUN chmod 755 /usr/local/bin/echidna
147+
148+ # Final setup and verification
149+ USER vscode
150+ RUN echo 'Development environment ready!' && \
151+ echo 'Tools installed:' && \
152+ ls -la $HOME/.local/bin/ || true
153+
154+ # Set working directory to workspace for development
155+ WORKDIR /workspace
0 commit comments