Skip to content

Commit

Permalink
support apt archive restriction
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Baudon committed Nov 25, 2024
1 parent 8df6dc0 commit c615901
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Check and, if you would like, change the following environment variables for the
| CRAN_REMOTE_URL | URL of the CRAN Remote repository (`https://cran.r-project.org/` by default) |
| APT_REMOTE_URL | URL of the APT Remote repository (`http://deb.debian.org/debian` by default) |
| APT_DISTRO | Name of the APT distribution (`bookworm` by default) |
| APT_ALLOWED_ARCHIVES | Comma-separated list of the authorized 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.
Expand Down
2 changes: 1 addition & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ timestamp() {
}

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

# Ensure allowlist files exist
Expand Down
11 changes: 9 additions & 2 deletions nexus_allowlist/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from nexus_allowlist.nexus import NexusAPI, RepositoryType
from nexus_allowlist.settings import (
ALLOWED_ARCHIVES,
APT_DISTRO,
APT_REMOTE_URL,
CRAN_REMOTE_URL,
Expand Down Expand Up @@ -277,7 +278,10 @@ def recreate_privileges(
nexus_api,
name="apt-all",
description="Allow access to all APT packages",
expression='format == "apt" and path=^"/pool/"',
expression=(
'format == "apt" and '
f'path=~"^/pool/({'|'.join(ALLOWED_ARCHIVES)})/.*"'
),
repo_type=_NEXUS_REPOSITORIES["apt_proxy"].repo_type,
repo=_NEXUS_REPOSITORIES["apt_proxy"].name,
)
Expand Down Expand Up @@ -317,7 +321,10 @@ def recreate_privileges(
nexus_api,
name=f"apt-{package}",
description=f"Allow access to {packages} APT package",
expression=f'format == "apt" and path=~"^/pool/.*/{package}.*"',
expression=(
'format == "apt" and '
f'path=~"^/pool/({'|'.join(ALLOWED_ARCHIVES)})/.*/{package}.*"'
),
repo_type=_NEXUS_REPOSITORIES["apt_proxy"].repo_type,
repo=_NEXUS_REPOSITORIES["apt_proxy"].name,
)
Expand Down
4 changes: 4 additions & 0 deletions nexus_allowlist/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@
CRAN_REMOTE_URL = os.getenv("CRAN_REMOTE_URL", "https://cran.r-project.org/")
APT_REMOTE_URL = os.getenv("APT_REMOTE_URL", "http://deb.debian.org/debian")
APT_DISTRO = os.getenv("APT_DISTRO", "bookworm")
ALLOWED_ARCHIVES = os.getenv(
"APT_ALLOWED_ARCHIVES",
"main,contrib,non-free-firmware,non-free"
).split(",")

0 comments on commit c615901

Please sign in to comment.