Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#69 add apt proxy repo support #70

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 30 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@ A [Dockerfile](Dockerfile) and example [docker compose](docker-compose.yaml) con

Check and, if you would like, change the following environment variables for the Nexus Allowlist container in [`docker-compose.yaml`](./docker-compose.yaml).

| Environment variable | meaning |
| ---------------------- | ------------------------------------------------------------------------------------------------------------- |
| NEXUS_ADMIN_PASSWORD | Password for the Nexus OSS admin user (changes from the default on first rune then used for authentication) |
| NEXUS_PACKAGES | Whether to allow all packages or only selected packages [`all`, `selected`] |
| NEXUS_HOST | Hostname of Nexus OSS host |
| NEXUS_PORT | Port of Nexus OSS |
| NEXUS_PATH | [Context path](https://help.sonatype.com/en/configuring-the-runtime-environment.html#changing-the-context-path) of Nexus OSS. Only used if the Nexus is hosted behind a reverse proxy with a URL like `https://your_url.domain/nexus/`. If not defined, the base URI remains `/`. |
| ENTR_FALLBACK | If defined, don't use `entr` to check for allowlist updates (this will be less reactive but we have found `entr` to not work in some situations) |

Example allowlist files are included in the repository for [PyPI](allowlists/pypi.allowlist) and [CRAN](allowlists/cran.allowlist).
| Environment variable | meaning |
| ---------------------- | ------------------------------------------------------------------------------------------------------------- |
| NEXUS_ADMIN_PASSWORD | Password for the Nexus OSS admin user (changes from the default on first rune then used for authentication) |
| NEXUS_PACKAGES | Whether to allow all packages or only selected packages [`all`, `selected`] |
| NEXUS_HOST | Hostname of Nexus OSS host |
| NEXUS_PORT | Port of Nexus OSS |
| NEXUS_PATH | [Context path](https://help.sonatype.com/en/configuring-the-runtime-environment.html#changing-the-context-path) of Nexus OSS. Only used if the Nexus is hosted behind a reverse proxy with a URL like `https://your_url.domain/nexus/`. If not defined, the base URI remains `/`. |
| ENTR_FALLBACK | If defined, don't use `entr` to check for allowlist updates (this will be less reactive but we have found `entr` to not work in some situations) |
| APT_URL | URL of the APT Remote repository (`http://deb.debian.org/debian` by default) |
| APT_RELEASE | Name of the APT distribution (`bookworm` by default) |
| APT_ARCHIVES | Allowed APT archives (`main contrib non-free-firmware non-free` by default) |

Example allowlist files are included in the repository for [PyPI](allowlists/pypi.allowlist), [CRAN](allowlists/cran.allowlist) and [APT](allowlists/apt.allowlist).
The PyPI allowlist includes numpy, pandas, matplotlib and their dependencies.
The CRAN allowlist includes cli and data.table
You can add more packages by writing the package names, one per line, in the allowlist files.
Expand Down Expand Up @@ -96,6 +99,22 @@ For example,
- `install.packages("data.table")` should succeed
- `install.packages("ggplot2")` should fail

#### APT

You can edit '/etc/apt/sources.list' to use the Nexus APT proxy.

For example

```
deb http://localhost:8080/repository/apt-proxy bookworm main
```

You should now only be able to install packages from the allowlist.
For example,

- `sudo apt install libcurl4-openssl-dev` should succeed
- `sudo apt install tcpdump` should fail

## Contributors ✨

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
Expand All @@ -119,4 +138,4 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d

<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
13 changes: 13 additions & 0 deletions allowlists/apt.allowlist
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
r-recommended
r-cran-matrixmodels
libcurl4-openssl-dev
libv8-dev
libxml2-dev
cmake
libfontconfig1-dev
libharfbuzz-dev
libfribidi-dev
libfreetype6-dev
libpng-dev
libtiff5-dev
libjpeg-dev
23 changes: 18 additions & 5 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,26 @@ export NEXUS_DATA_DIR=/nexus-data
export ALLOWLIST_DIR=/allowlists
export PYPI_ALLOWLIST="$ALLOWLIST_DIR"/pypi.allowlist
export CRAN_ALLOWLIST="$ALLOWLIST_DIR"/cran.allowlist
export APT_ALLOWLIST="$ALLOWLIST_DIR"/apt.allowlist

if [ -z "$APT_URL" ]; then
export APT_URL="https://deb.debian.org/debian"
fi

if [ -z "$APT_RELEASE" ]; then
export APT_RELEASE="bookworm"
fi

if [ -z "$APT_ARCHIVES" ]; then
export APT_ARCHIVES="main contrib non-free-firmware non-free"
fi

timestamp() {
date -Is
}

hashes() {
md5sum $PYPI_ALLOWLIST $CRAN_ALLOWLIST
md5sum $PYPI_ALLOWLIST $CRAN_ALLOWLIST $APT_ALLOWLIST
}

# Ensure allowlist files exist
Expand All @@ -37,7 +50,7 @@ nexus-allowlist --version
if [ -f "$NEXUS_DATA_DIR/admin.password" ]; then
echo "$(timestamp) Initial password file present, running initial configuration"
nexus-allowlist --admin-password "$NEXUS_ADMIN_PASSWORD" --nexus-host "$NEXUS_HOST" --nexus-path "$NEXUS_PATH" --nexus-port "$NEXUS_PORT" change-initial-password --path "$NEXUS_DATA_DIR"
nexus-allowlist --admin-password "$NEXUS_ADMIN_PASSWORD" --nexus-host "$NEXUS_HOST" --nexus-path "$NEXUS_PATH" --nexus-port "$NEXUS_PORT" initial-configuration --packages "$NEXUS_PACKAGES" --pypi-package-file "$ALLOWLIST_DIR/pypi.allowlist" --cran-package-file "$ALLOWLIST_DIR/cran.allowlist"
nexus-allowlist --admin-password "$NEXUS_ADMIN_PASSWORD" --nexus-host "$NEXUS_HOST" --nexus-path "$NEXUS_PATH" --nexus-port "$NEXUS_PORT" initial-configuration --packages "$NEXUS_PACKAGES" --pypi-package-file "$PYPI_ALLOWLIST" --cran-package-file "$CRAN_ALLOWLIST" --apt-package-file "$APT_ALLOWLIST" --apt-repository-url "$APT_URL" --apt-repository-release "$APT_RELEASE" --apt-repository-archives "$APT_ARCHIVES"
else
echo "$(timestamp) No initial password file found, skipping initial configuration"
fi
Expand All @@ -51,19 +64,19 @@ fi
if [ -n "$ENTR_FALLBACK" ]; then
echo "$(timestamp) Using fallback file monitoring"
# Run allowlist configuration now
nexus-allowlist --admin-password "$NEXUS_ADMIN_PASSWORD" --nexus-host "$NEXUS_HOST" --nexus-path "$NEXUS_PATH" --nexus-port "$NEXUS_PORT" update-allowlists --packages "$NEXUS_PACKAGES" --pypi-package-file "$PYPI_ALLOWLIST" --cran-package-file "$CRAN_ALLOWLIST"
nexus-allowlist --admin-password "$NEXUS_ADMIN_PASSWORD" --nexus-host "$NEXUS_HOST" --nexus-path "$NEXUS_PATH" --nexus-port "$NEXUS_PORT" update-allowlists --packages "$NEXUS_PACKAGES" --pypi-package-file "$PYPI_ALLOWLIST" --cran-package-file "$CRAN_ALLOWLIST" --apt-package-file "$APT_ALLOWLIST" --apt-repository-url "$APT_URL" --apt-repository-release "$APT_RELEASE" --apt-repository-archives "$APT_ARCHIVES"
# Periodically check for modification of allowlist files and run configuration again when they are
hash=$(hashes)
while true; do
new_hash=$(hashes)
if [ "$hash" != "$new_hash" ]; then
nexus-allowlist --admin-password "$NEXUS_ADMIN_PASSWORD" --nexus-host "$NEXUS_HOST" --nexus-path "$NEXUS_PATH" --nexus-port "$NEXUS_PORT" update-allowlists --packages "$NEXUS_PACKAGES" --pypi-package-file "$PYPI_ALLOWLIST" --cran-package-file "$CRAN_ALLOWLIST"
nexus-allowlist --admin-password "$NEXUS_ADMIN_PASSWORD" --nexus-host "$NEXUS_HOST" --nexus-path "$NEXUS_PATH" --nexus-port "$NEXUS_PORT" update-allowlists --packages "$NEXUS_PACKAGES" --pypi-package-file "$PYPI_ALLOWLIST" --cran-package-file "$CRAN_ALLOWLIST" --apt-package-file "$APT_ALLOWLIST" --apt-repository-url "$APT_URL" --apt-repository-release "$APT_RELEASE" --apt-repository-archives "$APT_ARCHIVES"
hash=$new_hash
fi
sleep 5
done
else
echo "$(timestamp) Using entr for file monitoring"
# Run allowlist configuration now, and again whenever allowlist files are modified
find "$ALLOWLIST_DIR"/*.allowlist | entr -n nexus-allowlist --admin-password "$NEXUS_ADMIN_PASSWORD" --nexus-host "$NEXUS_HOST" --nexus-path "$NEXUS_PATH" --nexus-port "$NEXUS_PORT" update-allowlists --packages "$NEXUS_PACKAGES" --pypi-package-file "$PYPI_ALLOWLIST" --cran-package-file "$CRAN_ALLOWLIST"
find "$ALLOWLIST_DIR"/*.allowlist | entr -n nexus-allowlist --admin-password "$NEXUS_ADMIN_PASSWORD" --nexus-host "$NEXUS_HOST" --nexus-path "$NEXUS_PATH" --nexus-port "$NEXUS_PORT" update-allowlists --packages "$NEXUS_PACKAGES" --pypi-package-file "$PYPI_ALLOWLIST" --cran-package-file "$CRAN_ALLOWLIST" --apt-package-file "$APT_ALLOWLIST" --apt-repository-url "$APT_URL" --apt-repository-release "$APT_RELEASE" --apt-repository-archives "$APT_ARCHIVES"
fi
1 change: 1 addition & 0 deletions integration_tests/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ RUN apk add --no-cache --update python3 py3-pip R
RUN mkdir -p /root/.config/pip
COPY pip.conf /root/.config/pip/pip.conf
COPY Rprofile /root/.Rprofile
COPY sources.list /etc/apt/sources.list
1 change: 1 addition & 0 deletions integration_tests/sources.list
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
deb http://localhost:8080/repository/apt-proxy bookworm main
2 changes: 1 addition & 1 deletion nexus_allowlist/__about__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "v0.11.0"
__version__ = "v0.12.0"
Loading
Loading