Skip to content

Commit b73a2c2

Browse files
authored
Proof-of-concept use of Ploutos to create RPM and DEB packages (#72)
* WIP * WIP * Test DEB too. * Move package.metadata to the workspace member Cargo.toml because cargo read-manifest complains otherwise about missing package.name in the root Cargo.toml. * Install clang for libclang needed by sudo-pam-sys build.rs. * Add copyright needed by cargo-deb. * Move copyright key to correct TOML table? * Add maintainer key needed by cargo-deb. * Install libclang for Debian/Ubuntu builds. * Also install libpam-dev. * Maintainer must contain an email address or else Lintian complains with error malformed-contact. * Extended description must be defined or else Lintian complains with error extended-description-is-empty. * Add a test script. * Setuid in DEB as well as RPM packages. * Should the paths be relative to the workspace root? * Use workspace inheritance and standard Cargo settings where possible instead of custom packaging tool settings. * Fix rpmlint warning 'invalid-license Apache-2.0' by using the correct license string. * TOML syntax fix. * Work around apt error 'E: Packages were downgraded and -y was used without --allow-downgrades.' presumably due to existing sudo package by same name but higher version. * Oops, don't break Cargo workspace project relationship. * Package conflicts with existing sudo package, but presumably test install still fails when the original sudo package is present. * Ah cargo-deb *does* support Breaks and Replaces. * Play nicely with the existing sudo package. * Fix path to maintainer-scripts. * Use the release Ploutos v7.
1 parent e2e8e8b commit b73a2c2

File tree

6 files changed

+69
-0
lines changed

6 files changed

+69
-0
lines changed

.github/workflows/pkg.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
on:
2+
push:
3+
workflow_dispatch:
4+
5+
jobs:
6+
package:
7+
uses: NLnetLabs/ploutos/.github/workflows/pkg-rust.yml@v7
8+
with:
9+
workspace_package: sudo
10+
11+
package_build_rules: |
12+
pkg: sudo-rs
13+
image:
14+
- "rockylinux:8"
15+
- "ubuntu:jammy"
16+
target: x86_64
17+
18+
package_test_scripts_path: pkg/test-scripts/test-sudo-rs.sh
19+
20+
deb_extra_build_packages: libclang-dev libpam-dev
21+
22+
rpm_extra_build_packages: pam-devel clang
23+
rpm_scriptlets_path: pkg/rpm/scriptlets.toml

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ license = "Apache-2.0 OR MIT"
1919
edition = "2021"
2020
repository = "https://github.com/memorysafety/sudo-rs"
2121
homepage = "https://github.com/memorysafety/sudo-rs"
22+
description = "A memory safe implementation of sudo and su"
23+
readme = "README.md"
2224
publish = true
2325

2426
[workspace.dependencies]

pkg/deb/postinst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash -e
2+
chmod +s /usr/bin/sudo-rs

pkg/rpm/scriptlets.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
post_install_script = '''
2+
#!/bin/bash -e
3+
chmod +s /usr/bin/sudo-rs
4+
'''

pkg/test-scripts/test-sudo-rs.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
3+
set -eo pipefail
4+
set -x
5+
6+
case $1 in
7+
post-install|post-upgrade)
8+
[[ $(find /usr/bin/sudo-rs -perm -g=s -exec echo SUDO-RS-HAS-SETUID \;) == "SUDO-RS-HAS-SETUID" ]]
9+
;;
10+
esac

sudo/Cargo.toml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ license.workspace = true
66
repository.workspace = true
77
homepage.workspace = true
88
publish.workspace = true
9+
readme.workspace = true
10+
description.workspace = true
911
categories = ["command-line-interface"]
1012

1113
[dependencies]
@@ -14,3 +16,29 @@ sudo-system.workspace = true
1416
sudo-cli.workspace = true
1517
sudoers.workspace = true
1618
sudo-pam.workspace = true
19+
20+
[package.metadata.deb]
21+
name = "sudo-rs"
22+
copyright = "Copyright (c) 2022-2023 Internet Security Research Group"
23+
maintainer = "Prossimo (ISRG) <[email protected]>"
24+
maintainer-scripts = "../pkg/deb/"
25+
# Until we think it is safe to actually replace the real sudo package, don't
26+
# mark it as breaking or replacing the real sudo package and don't attempt to
27+
# overwrite /usr/bin/sudo, instead explicitly via assets install it under new
28+
# name /usr/bin/sudo-rs
29+
#breaks = "sudo"
30+
#replaces = "sudo"
31+
assets = [
32+
["target/release/sudo", "/usr/bin/sudo-rs", "755"]
33+
]
34+
35+
[package.metadata.generate-rpm]
36+
# See: https://fedoraproject.org/wiki/Licensing:Main?rd=Licensing#Good_Licenses
37+
license = "ASL 2.0"
38+
# Until we think it is safe to actually replace the real sudo package, don't
39+
# mark it as obsoleting the real sudo package and don't attempt to overwrite
40+
# /usr/bin/sudo, instead install it under new name /usr/bin/sudo-rs.
41+
#obsoletes = "sudo"
42+
assets = [
43+
{ source = "target/release/sudo", dest = "/usr/bin/sudo-rs", mode = "755" }
44+
]

0 commit comments

Comments
 (0)