Skip to content

Commit e7f3971

Browse files
committed
Add conf-files statement to Cargo.toml to preserve configuration on upgrades for deb package; switch to SPDX license definition; add RPM build; add build.sh for local containerized builds; add support for glibc 2.17; add support for Ubuntu/RHEL update README; bump version to 1.1.0
1 parent 36276e1 commit e7f3971

File tree

7 files changed

+153
-39
lines changed

7 files changed

+153
-39
lines changed

.github/workflows/ci.yaml

+27-7
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@ jobs:
1010
build_release:
1111
name: build and release
1212
runs-on: ubuntu-20.04 # Build on Debian-based distro
13+
container: quay.io/pypa/manylinux2014_x86_64 # Use a container with glibc 2.17
1314
steps:
14-
- name: Checkout
15+
16+
- name: Show GLIBC # Confirm glibc version
17+
run: ldd --version
18+
19+
- name: Checkout # Clone repository
1520
uses: actions/checkout@v2
1621
with:
1722
fetch-depth: 0
@@ -21,22 +26,37 @@ jobs:
2126
export VERSION=${{github.ref_name}}
2227
sed -i "s/0.0.0/$VERSION/g" Cargo.toml
2328
24-
- name: Cargo build
29+
- name: Install stable toolchain # Install Rust
30+
uses: actions-rs/toolchain@v1
31+
with:
32+
profile: minimal
33+
toolchain: stable
34+
override: true
35+
36+
- name: Cargo build # Release build
2537
run: |
2638
cargo build --release --verbose
2739
ls -lah target/release
2840
29-
- name: Cargo deb
41+
- name: Cargo deb # deb package
3042
run: |
3143
cargo install --version 1.44.1 cargo-deb
3244
cargo deb --verbose
3345
ls -lah target/debian
3446
35-
- name: Release
47+
- name: Cargo rpm # RPM package
48+
run: |
49+
cargo install --version 0.14.0 cargo-generate-rpm
50+
strip -s target/release/libnss_shim.so
51+
cargo generate-rpm --payload-compress none
52+
ls -lah target/generate-rpm
53+
54+
- name: Release # Publish GitHub release
3655
uses: softprops/action-gh-release@v1
37-
if: startsWith(github.ref, 'refs/tags/') # Presumably redundant due to the [0-9] filter, but kept for safety
56+
if: startsWith(github.ref, 'refs/tags/') # Presumably redundant due to the `on: push: tags:` filter, but kept for safety
3857
with:
39-
body_path: ${{github.workspace}}/changelog/CHANGELOG.txt # Get the release notes from the changelog file
40-
fail_on_unmatched_files: true
58+
body_path: ${{github.workspace}}/changelog/CHANGELOG.txt # Add the release notes from the changelog file
59+
fail_on_unmatched_files: true # Ensure all packages built, to avoid publishing an incomplete release
4160
files: |
4261
target/debian/*.deb
62+
target/generate-rpm/*.rpm

Cargo.lock

+11-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+16-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ authors = ["Noah Kruiper"]
55
edition = "2021"
66
description = "NSS module shim to use custom sources for group/passwd/shadow lookups"
77
readme = "README.md"
8-
license-file = "LICENSE"
8+
license = "GPL-3.0-or-later"
99
repository = "https://github.com/xenago/libnss_shim"
1010

1111
# Reduce size when building for release
@@ -16,11 +16,11 @@ codegen-units = 1 # use a single thread
1616

1717
[dependencies]
1818
lazy_static = "1.4.0"
19-
libc = "0.2.152"
19+
libc = "0.2.155"
2020
libnss = "0.4"
21-
paste = "1.0.14"
22-
serde = { version = "1.0.195", features = ["derive"] }
23-
serde_json = "1.0.111"
21+
paste = "1.0.15"
22+
serde = { version = "1.0.203", features = ["derive"] }
23+
serde_json = "1.0.117"
2424
shlex = "1.3.0"
2525

2626
[lib]
@@ -37,4 +37,15 @@ assets = [
3737
["default_config/config.json", "etc/libnss_shim/config.json", "640"],
3838
["README.md", "usr/share/doc/libnss_shim/README", "644"],
3939
]
40+
conf-files = ["etc/libnss_shim/config.json"]
4041
maintainer-scripts = "debian"
42+
43+
[package.metadata.generate-rpm]
44+
summary = "A plugin for the Name Service Switch (NSS) framework that parses the output of commands to resolve queries."
45+
assets = [
46+
{ source = "target/release/libnss_shim.so", dest = "/lib64/libnss_shim.so.2", mode = "644", config = false, doc = false, user = "root", group = "root" },
47+
{ source = "default_config/config.json", dest = "/etc/libnss_shim/config.json", mode = "640", config = true, doc = false, user = "root", group = "root" },
48+
{ source = "README.md", dest = "/usr/share/doc/libnss_shim/README", mode = "644", config = false, doc = true, user = "root", group = "root" },
49+
]
50+
post_install_script = "debian/postinst"
51+
post_uninstall_script = "debian/postrm"

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ Public License instead of this License. But first, please read
678678
The following notice applies to all files in the package, unless a different copyright notice is defined within:
679679

680680
libnss_shim
681-
Copyright (c) 2023 Noah Kruiper
681+
Copyright (c) 2024 Noah Kruiper
682682

683683
This program is free software: you can redistribute it and/or modify
684684
it under the terms of the GNU General Public License as published by

README.md

+54-14
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,45 @@ can print to `stdout` in a supported format to be used with NSS.
3131

3232
### Compatibility notes
3333

34-
- Tested on Debian-based GNU/Linux distributions
34+
- Tested on:
35+
- CentOS 7
36+
- AlmaLinux 8
37+
- AlmaLinux 9
38+
- Debian 11
39+
- Debian 12
40+
- Ubuntu 20.04
41+
- Ubuntu 22.04
42+
- Ubuntu 24.04
3543
- Builds for `amd64` architecture
36-
- If `.deb` packages are not supported on the desired target platform, `libnss_shim` might be usable if the `assets` as
37-
described in `Cargo.toml` are installed prior to running the `debian/postinst` script, but this has not been tested
44+
- Packaged in `.deb` and `.rpm` formats
45+
- If available packages do not work on a target platform, `libnss_shim` might be usable if the `assets` are installed
46+
as described in `Cargo.toml` prior to running the `debian/postinst` script, but this has not been tested extensively.
3847
- To request support for a different configuration, please create a GitHub Issue
3948

4049
### Installation steps
4150

4251
1. Prepare the commands/software that will be triggered by `libnss_shim` (see the Commands section for details).
4352

44-
2. Download the latest release produced by GitHub Actions:
53+
2. Download the latest release produced by GitHub Actions.
54+
55+
**deb:**
56+
```
57+
wget https://github.com/xenago/libnss_shim/releases/download/1.1.0/libnss_shim_1.1.0_amd64.deb
4558
```
46-
wget https://github.com/xenago/libnss_shim/releases/download/1.0.5/libnss_shim_1.0.5_amd64.deb
59+
**RPM:**
4760
```
61+
wget https://github.com/xenago/libnss_shim/releases/download/1.1.0/libnss_shim-1.1.0-1.x86_64.rpm
62+
```
63+
64+
3. Install it directly `dpkg` or `rpm`.
4865
49-
3. Install it directly with `dpkg` or through `apt`:
66+
**deb:**
5067
```
51-
sudo dpkg -i libnss_shim_1.0.5_amd64.deb
68+
sudo dpkg -i libnss_shim_1.1.0_amd64.deb
5269
```
53-
or
70+
**RPM:**
5471
```
55-
sudo apt install ./libnss_shim_1.0.5_amd64.deb
72+
sudo rpm -i ./libnss_shim-1.1.0-1.x86_64.rpm
5673
```
5774
5875
4. Configure the shim by importing a custom `config.json`:
@@ -328,11 +345,34 @@ testing purposes. Environment variables are generally private, whereas commands/
328345
Commands are not passed through a shell for execution. Although it is possible to run software like `bash`
329346
with `libnss_shim`, using a shell is not recommended as this comes with additional risks such as command injection.
330347
348+
## Development
349+
350+
When building locally, using [`act`](https://github.com/nektos/act) can be helpful to run `.github/ci.yaml` directly.
351+
Depending on your configuration, some tweaks may be required to enable it to build successfully.
352+
353+
I generally find it easiest to run `build.sh` inside a temporary container:
354+
355+
1. Ensure `Docker` is installed and available
356+
2. Ensure `libnss_shim` is cloned:
357+
358+
git clone https://github.com/xenago/libnss_shim.git
359+
360+
3. Run the build script inside a temporary container, setting `LIBNSS_SHIM_VERSION` and the cloned repo path as desired:
361+
362+
sudo docker run -e "LIBNSS_SHIM_VERSION=0.0.0" -v /path/to/cloned/libnss_shim:/libnss_shim --rm quay.io/pypa/manylinux2014_x86_64:latest bash /libnss_shim/build.sh
363+
364+
4. The build script will output packages in the following subdirectories of the cloned repo:
365+
366+
* `target/debian/*.deb`
367+
* `target/generate-rpm/*.rpm`
368+
331369
## Useful resources
332370
333-
- NSS Modules Interface
371+
- *Building Rust binaries in CI that work with older GLIBC*
372+
- Jakub Beránek, AKA Kobzol's [blog](https://kobzol.github.io/rust/ci/2021/05/07/building-rust-binaries-in-ci-that-work-with-older-glibc.html)
373+
- *NSS Modules Interface*
334374
- The GNU C [library](https://www.gnu.org/software/libc/manual/html_node/NSS-Modules-Interface.html)
335-
- Actions in the NSS configuration
375+
- *Actions in the NSS configuration*
336376
- The GNU C [library](https://www.gnu.org/software/libc/manual/html_node/Actions-in-the-NSS-configuration.html)
337377
- Rust bindings for `libnss`
338378
- The `libnss` [crate](https://crates.io/crates/libnss)
@@ -342,11 +382,11 @@ with `libnss_shim`, using a shell is not recommended as this comes with addition
342382
- The `nss-wiregarden` [crate](https://crates.io/crates/libnss-wiregarden)
343383
- Example of parsing `passwd` and `group` formats with Rust
344384
- The `parsswd` [crate](https://crates.io/crates/parsswd)
345-
- Testing NSS modules in glibc
385+
- *Testing NSS modules in glibc*
346386
- Geoffrey Thomas's [blog](https://ldpreload.com/blog/testing-glibc-nsswitch)
347-
- NSS - Debathena (useful description of NSS and how it fits into their architecture)
387+
- *NSS - Debathena* (useful description of NSS and how it fits into their architecture)
348388
- MIT Debathena [wiki](https://debathena.mit.edu/trac/wiki/NSS)
349-
- Debathena hacks (links to more NSS-related code for their project)
389+
- *Debathena hacks* (links to more NSS-related code for their project)
350390
- MIT Debathena [website](https://debathena.mit.edu/hacks)
351391
- Debathena NSS module source example
352392
- MIT Debathena [repository](https://debathena.mit.edu/packages/debathena/libnss-afspag/libnss-afspag-1.0/)

build.sh

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/sh
2+
set -e
3+
4+
cd /libnss_shim
5+
6+
echo "BUILD: Setting version to $LIBNSS_SHIM_VERSION"
7+
sed -i "s/0.0.0/$LIBNSS_SHIM_VERSION/g" Cargo.toml
8+
9+
echo "BUILD: Installing Rust"
10+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
11+
. "$HOME/.cargo/env"
12+
13+
echo "BUILD: Building for release"
14+
cargo build --release --verbose
15+
echo "BUILD: built for release"
16+
ls -lah target/release
17+
18+
echo "BUILD: Packaging deb"
19+
cargo install --version 1.44.1 cargo-deb
20+
cargo deb --verbose
21+
echo "BUILD: deb packaged"
22+
ls -lah target/debian
23+
24+
echo "BUILD: Packaging RPM"
25+
cargo install --version 0.14.0 cargo-generate-rpm
26+
strip -s target/release/libnss_shim.so
27+
cargo generate-rpm --payload-compress none
28+
echo "BUILD: RPM packaged"
29+
ls -lah target/generate-rpm

changelog/CHANGELOG.txt

+15-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,15 @@
1-
1+
- Support EL distros with RPM package
2+
- Define `conf-files` for deb package to preserve `config.json` on upgrades
3+
- Switch build container to `quay.io/pypa/manylinux2014_x86_64` to support `glibc` version `2.17`
4+
- Test `glibc 2.17` RPM build on CentOS 7, AlmaLinux 8, and AlmaLinux 9
5+
- Test `glibc 2.17` deb build on Debian 10, 11, and 12
6+
- Test `glibc 2.17` deb build on Ubuntu 20.04, 22.04, and 24.04
7+
- Define `conf-files` for deb package to preserve `config.json` on deb package upgrades
8+
- Bump `libc` to `0.2.155`
9+
- Bump `paste` to `1.0.15`
10+
- Bump `serde` to `1.0.203`
11+
- Bump `serde_json` to `1.0.117`
12+
- Add local build script `build.sh`
13+
- Add local build instructions to README.md
14+
- Use SPDX format for license
15+
- Update copyright year

0 commit comments

Comments
 (0)