Skip to content

Commit f9fc7d2

Browse files
authored
Merge branch 'main' into dev
2 parents 5a960a0 + 180b9dc commit f9fc7d2

File tree

41 files changed

+278
-454
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+278
-454
lines changed

.github/workflows/build.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ jobs:
2727
account required pam_permit.so
2828
session [success=1 default=ignore] pam_permit.so
2929
session requisite pam_permit.so
30-
session required pam_permit.so" | tee /etc/pam.d/dosr'
30+
session required pam_permit.so" | tee /etc/pam.d/sr'
3131
- name: Install RootAsRole
3232
run: cargo xtask install -bip sudo
3333
- name: print config
34-
run: dosr cat /etc/security/rootasrole.json
34+
run: sr cat /etc/security/rootasrole.json
3535
- name: getenv
3636
run: env
37-
- name: Run dosr
37+
- name: Run Sr
3838
env:
3939
RUST_LOG: debug
40-
run: /usr/bin/dosr -h
41-
- name: Run Chsr with dosr
42-
run: dosr /usr/bin/chsr -h
40+
run: /usr/bin/sr -h
41+
- name: Run Chsr with sr
42+
run: sr /usr/bin/chsr -h

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"type": "lldb",
99
"request": "launch",
1010
"name": "Launch",
11-
"program": "${workspaceFolder}/target/debug/dosr",
11+
"program": "${workspaceFolder}/target/debug/sr",
1212
"args": ["ls"],
1313
"cwd": "${workspaceFolder}"
1414
}

.vscode/tasks.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"args": [
1515
"/usr/bin/setcap",
1616
"=p",
17-
"${cwd}/bin/dosr"
17+
"${cwd}/bin/sr"
1818
],
1919
"options": {
2020
"cwd": "${cwd}"

Cargo.toml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ version = "3.1.3"
88
rust-version = "1.76.0"
99
authors = ["Eddie Billoir <[email protected]>"]
1010
edition = "2021"
11-
default-run = "dosr"
11+
default-run = "sr"
1212
description = "An alternative to sudo that uses Linux capabilities and Role based access control."
1313
license = "LGPL-3.0-or-later"
1414
repository = "https://github.com/LeChatP/RootAsRole"
@@ -41,7 +41,7 @@ debug = true
4141
#srlibs = [ "pam-client", "bitflags" ]
4242

4343
[[bin]]
44-
name = "dosr"
44+
name = "sr"
4545
path = "src/sr/main.rs"
4646
required-features = ["finder"]
4747

@@ -76,7 +76,8 @@ serde = { version = "1.0", features=["rc", "derive"] }
7676
serde_json = "1.0"
7777
cbor4ii = { version = "1.0.0", features = ["serde", "serde1", "use_std"] }
7878
glob = "0.3"
79-
bitflags = { version = "2.9" }
79+
pam-client2 = "0.5"
80+
bitflags = { version = "2.6" }
8081
shell-words = "1.1"
8182
linked_hash_set = { version = "0.1" }
8283
derivative = "2.2"
@@ -88,11 +89,9 @@ pest = "2.7"
8889
pest_derive = "2.7"
8990
const_format = "0.2"
9091
hex = "0.4"
91-
bon = "3"
92-
serde_json_borrow = "0.8"
93-
konst = "0.3"
94-
nonstick = "0.1.1"
95-
libpam-sys = "0.2.0"
92+
bon = "3.5.1"
93+
serde_json_borrow = "0.7.1"
94+
konst = "0.3.16"
9695

9796
[dev-dependencies]
9897
log = "0.4"
@@ -122,7 +121,7 @@ changelog = "target/debian/changelog"
122121

123122
[package.metadata.generate-rpm]
124123
assets = [
125-
{ source = "target/release/dosr", dest = "/usr/bin/dosr", user = "root", group = "root", mode = "0555", caps = "=p" },
124+
{ source = "target/release/sr", dest = "/usr/bin/sr", user = "root", group = "root", mode = "0555", caps = "=p" },
126125
{ source = "target/release/chsr", dest = "/usr/bin/chsr", user = "root", group = "root", mode = "0555" },
127126
{ source = "resources/rh/rh_sr_pam.conf", dest = "/etc/pam.d/sr", user = "root", group = "root", mode = "0644", config = true },
128127
{ source = "resources/rootasrole.json", dest = "/etc/security/rootasrole.json", user = "root", group = "root", mode = "0644", config = true },

README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<!-- The project version is managed on json file in resources/rootasrole.json -->
1515
<!-- markdownlint-restore -->
1616

17-
# RootAsRole (V3.1.3) — A better alternative to `sudo(-rs
17+
# RootAsRole (V3.1.3) — A better alternative to `sudo(-rs)`/`su` • ⚡ Blazing fast • 🛡️ Memory-safe • 🔐 Security-oriented
1818

1919
RootAsRole is a Linux/Unix privilege delegation tool based on **Role-Based Access Control (RBAC)**. It empowers administrators to assign precise privileges — not full root — to users and commands.
2020

@@ -44,7 +44,7 @@ RootAsRole solves this:
4444

4545
## 📊 Why It’s Better Than Others
4646

47-
| Feature | setcap?? | doas | sudo | sudo-rs | dosr (RootAsRole) |
47+
| Feature | setcap?? | doas | sudo | sudo-rs | sr (RootAsRole) |
4848
|------------------------------------------|-------------------|------------|--------------------------------|--------------------------------|----------------------------------------------|
4949
| **Change user/groups** | N/A |||| ✅✅ mandatory or optional |
5050
| **Environment variables** | N/A | partial || partial ||
@@ -97,7 +97,7 @@ RootAsRole solves this:
9797
<pre>
9898
Execute privileged commands with a role-based access control system
9999

100-
<u><b>Usage</b></u>: <b>dosr</b> [OPTIONS] [COMMAND]...
100+
<u><b>Usage</b></u>: <b>sr</b> [OPTIONS] [COMMAND]...
101101

102102
<u><b>Arguments</b></u>:
103103
[COMMAND]... Command to execute
@@ -116,8 +116,7 @@ Execute privileged commands with a role-based access control system
116116

117117
If you're accustomed to utilizing the sudo tool and find it difficult to break that habit, consider creating an alias :
118118
```sh
119-
alias sudo="dosr"
120-
alias sr="dosr"
119+
alias sudo="sr"
121120
```
122121
123122
## 🏎️ Performance
@@ -133,7 +132,7 @@ RootAsRole **3.1.0** introduced **CBOR** support, significantly boosting perform
133132
134133
### Why Performance Matters
135134
136-
When using **Ansible** (or any automation tool), every task that uses `become: true` will invoke `dosr` on the target host.
135+
When using **Ansible** (or any automation tool), every task that uses `become: true` will invoke `sr` on the target host.
137136
With **RootAsRole (RaR)**, each role and task introduces additional access control logic --- this doesn’t slow you down.
138137
139138
💡 **Here’s the reality**: You can reach the performance of **1 `sudo` rule** with **~4000 RaR rules**.

book/src/README.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717

1818
## Usage
1919

20-
The main command line tool is `dosr`. It allows you to execute a command by simply typing:
20+
The main command line tool is `sr`. It allows you to execute a command by simply typing:
2121

2222
```bash
23-
dosr <command>
23+
sr <command>
2424
```
2525

26-
You can find more information about this command in the [dosr](sr/README.md) section.
26+
You can find more information about this command in the [sr](sr/README.md) section.
2727

2828
The `chsr` command allows you to configure the roles and capabilities of the system. You can find more information about this command in the [Configure RootAsRole](chsr/README.md) section.
2929

@@ -51,43 +51,43 @@ By using a role-based access control model, this project allows us to better man
5151
You are using your personal computer and you want to install a new package. By default, RootAsRole add one role with 2 tasks : one task for using `chsr` command that grant only the `CAP_LINUX_IMMUTABLE` capability as `root` user (unprivileged), and one task for all commands but without `CAP_LINUX_IMMUTABLE` privilege. As installing a package may require almost all capabilities, you can use the default role to install a package. Indeed, if you wish to install apache2, you'll need `CAP_NET_BIND_SERVICE`, if you install docker you'll need many privileges, virtualbox needs `CAP_SYS_MODULE`, etc. So, you can use the default role to install a package:
5252

5353
```bash
54-
dosr apt install <package>
54+
sr apt install <package>
5555
```
5656

5757
### Scenario 2: Granting users the right to restart their system
5858

5959
You are the system administrator of a company and you want to delegate the right to restart the server to a user. You can use `chsr` to create a role and grant the right to restart the server to users.
6060

6161
```bash
62-
dosr chsr role r_users add # Create a new role
63-
dosr chsr role r_users grant -g users # Grant the role to the group users
64-
dosr chsr role r_users task t_reboot add # Create a new task
65-
dosr chsr role r_users task t_reboot cmd whitelist add reboot # Add the reboot command to the task
66-
dosr chsr role r_users task t_reboot cred caps whitelist add CAP_SYS_BOOT # Add the CAP_SYS_BOOT capability to the task
62+
sr chsr role r_users add # Create a new role
63+
sr chsr role r_users grant -g users # Grant the role to the group users
64+
sr chsr role r_users task t_reboot add # Create a new task
65+
sr chsr role r_users task t_reboot cmd whitelist add reboot # Add the reboot command to the task
66+
sr chsr role r_users task t_reboot cred caps whitelist add CAP_SYS_BOOT # Add the CAP_SYS_BOOT capability to the task
6767
```
6868

6969
Then users can restart the server with the following command:
7070

7171
```bash
72-
dosr reboot
72+
sr reboot
7373
```
7474

7575
### Scenario 3 : Passing environment variables to a command
7676

7777
You are a developer and you want to pass environment variables to a command. For example with sudo you can use the `-E` option to pass environment variables to a command. With RootAsRole, you'll need to setup a role with a task that allows the command to use environment variables. However, as you keep the default configuration, you'll have two roles that matches ANY commands, and if the first one is more restrictive than the second one, you'll need to specify the role to use. Here is an example:
7878

7979
```bash
80-
dosr chsr role env add # Create a new role
81-
dosr chsr role env task env add # Create a new task
82-
dosr chsr role env task env cmd setpolicy allow-all # Add all command to the task
83-
dosr chsr role env task env cred caps setpolicy allow-all # Add all capabilities to the task
84-
dosr chsr role env task env o env setpolicy keep-all # Keep the environment variables
80+
sr chsr role env add # Create a new role
81+
sr chsr role env task env add # Create a new task
82+
sr chsr role env task env cmd setpolicy allow-all # Add all command to the task
83+
sr chsr role env task env cred caps setpolicy allow-all # Add all capabilities to the task
84+
sr chsr role env task env o env setpolicy keep-all # Keep the environment variables
8585
```
8686

8787
Then you can use the following command to pass environment variables to a command:
8888

8989
```bash
90-
dosr -r env [command]
90+
sr -r env [command]
9191
```
9292

9393
This is because the default role do not keep the environment variables, so if you want to keep environment variables you need to specify the role to use.
@@ -97,26 +97,26 @@ This is because the default role do not keep the environment variables, so if yo
9797
You are an administrator that want to automatically reboot the system at 04:05 every day with cron for example. You can disable authentication by setting skip-auth in the options. Here is an example:
9898

9999
```bash
100-
dosr chsr role auto add # Create a new role
101-
dosr chsr role grant -u cron # Grant the role to the user cron
102-
dosr chsr role auto task cron_reboot add # Create a new task
103-
dosr chsr role auto task cron_reboot cmd whitelist add reboot # Add the reboot command to the task
104-
dosr chsr role auto task cron_reboot cred caps whitelist add CAP_SYS_BOOT # Add the CAP_SYS_BOOT capability to the task
105-
dosr chsr role auto task cron_reboot o authentication skip # Skip authentication
100+
sr chsr role auto add # Create a new role
101+
sr chsr role grant -u cron # Grant the role to the user cron
102+
sr chsr role auto task cron_reboot add # Create a new task
103+
sr chsr role auto task cron_reboot cmd whitelist add reboot # Add the reboot command to the task
104+
sr chsr role auto task cron_reboot cred caps whitelist add CAP_SYS_BOOT # Add the CAP_SYS_BOOT capability to the task
105+
sr chsr role auto task cron_reboot o authentication skip # Skip authentication
106106
```
107107

108108
Then you can configure the cron to reboot the system with the following command:
109109

110110
```bash
111-
dosr crontab -u cron -e
111+
sr crontab -u cron -e
112112
```
113113

114114
and add the following line to reboot the system at 04:05 every day
115115

116116
```cron
117-
5 4 * * * dosr -r auto -t cron_reboot reboot
117+
5 4 * * * sr -r auto -t cron_reboot reboot
118118
```
119119

120-
Note: You should consider to set the `-r auto -t cron_reboot` options to the `dosr` command when you automate a task to avoid any security issue or future conflict.
120+
Note: You should consider to set the `-r auto -t cron_reboot` options to the `sr` command when you automate a task to avoid any security issue or future conflict.
121121

122122
For a more complete example, you can checkout the [Is a Linux system without root user possible ?](knowledge/no-root.md) section.

book/src/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# User Guide
77

88
- [Installation](guide/installation.md)
9-
- [`dosr` Command Line Tool](dosr/README.md)
9+
- [`sr` Command Line Tool](sr/README.md)
1010
- [`chsr` Command Line Tool](chsr/README.md)
1111
- [`capable` Command Line Tool](capable/README.md)
1212

book/src/chsr/file-config.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ The following example shows a RootAsRole config without plugins when almost ever
9393
"cred": {
9494
"setuid": {
9595
"fallback": "thefallbackuser", // Fallback user if the -u option is not set
96-
"default": "none", // The dosr user cannot use -u option in general
97-
"add": ["theuser"], // the dosr user can use "-u theuser" option
98-
"sub": ["anotheruser"] // the dosr user cannot use "-u anotheruser" option (overrides add, applies only if default is all)
96+
"default": "none", // The sr user cannot use -u option in general
97+
"add": ["theuser"], // the sr user can use "-u theuser" option
98+
"sub": ["anotheruser"] // the sr user cannot use "-u anotheruser" option (overrides add, applies only if default is all)
9999
}, // User to setuid before executing the command
100100
"setgid": [ // Groups to setgid before executing the command, The first one is the primary group
101101
"group1",

book/src/guide/installation.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ Install script does the following:
2828
- Dependency Step :
2929
- Installing necessary dependencies considering if compiling from source.
3030
- Build Step :
31-
- Building dosr and chsr binaries
31+
- Building sr and chsr binaries
3232
- Install Step :
33-
- Copying dosr and chsr binaries to /usr/bin
34-
- Setting all capabilities on /usr/bin/dosr
35-
- Setting owners and permissions on /usr/bin/dosr
33+
- Copying sr and chsr binaries to /usr/bin
34+
- Setting all capabilities on /usr/bin/sr
35+
- Setting owners and permissions on /usr/bin/sr
3636
- Configuration Step :
37-
- Deploying /etc/pam.d/dosr for PAM configuration
37+
- Deploying /etc/pam.d/sr for PAM configuration
3838
- Deploying /etc/security/rootasrole.json for configuration
3939
- Setting immutable on /etc/security/rootasrole.json if filesytem supports it

book/src/knowledge/no-root.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,35 @@
33
To make it short, not really. But you can design your system to never have to use the root user. This is what RootAsRole aims, and the exact purpose of Linux Capabilities. Let's consider you want a system without root user and you want to setup a webserver. Firstly, let's create the apache2 user and group:
44

55
```bash
6-
dosr adduser apache2
6+
sr adduser apache2
77
```
88

99
We consider that we still use the default configuration of RootAsRole. Then, let's add a task to install apache2 with the apache2 user:
1010

1111
```bash
12-
dosr chsr r r_root t install_apache2 add
13-
dosr chsr r r_root t install_apache2 cmd whitelist add apt install apache2
14-
dosr chsr r r_root t install_apache2 cmd whitelist add "apt upgrade( -y)? apache2"
15-
dosr chsr r r_root t install_apache2 cred set --caps CAP_CHOWN,CAP_DAC_OVERRIDE,CAP_NET_BIND_SERVICE,CAP_SETUID --setuid apache2 --setgid apache2
12+
sr chsr r r_root t install_apache2 add
13+
sr chsr r r_root t install_apache2 cmd whitelist add apt install apache2
14+
sr chsr r r_root t install_apache2 cmd whitelist add "apt upgrade( -y)? apache2"
15+
sr chsr r r_root t install_apache2 cred set --caps CAP_CHOWN,CAP_DAC_OVERRIDE,CAP_NET_BIND_SERVICE,CAP_SETUID --setuid apache2 --setgid apache2
1616
```
1717

1818
Then, let's add a task to start apache2 with the apache2 user:
1919

2020
```bash
21-
dosr chsr r r_root t start_apache2 add
22-
dosr chsr r r_root t start_apache2 cmd whitelist add "systemctl ((re)?start|stop) apache2"
23-
dosr chsr r r_root t start_apache2 cmd whitelist add "service apache2 ((re)?start|stop)"
24-
dosr chsr r r_root t install_apache2 cred set --caps CAP_NET_BIND_SERVICE,CAP_SETUID --setuid apache2 --setgid apache2
21+
sr chsr r r_root t start_apache2 add
22+
sr chsr r r_root t start_apache2 cmd whitelist add "systemctl ((re)?start|stop) apache2"
23+
sr chsr r r_root t start_apache2 cmd whitelist add "service apache2 ((re)?start|stop)"
24+
sr chsr r r_root t install_apache2 cred set --caps CAP_NET_BIND_SERVICE,CAP_SETUID --setuid apache2 --setgid apache2
2525
```
2626

2727
So now you can install and start apache2 with the apache2 user:
2828

2929
```bash
30-
dosr apt install apache2
30+
sr apt install apache2
3131
```
3232

3333
This should install apache2 configuration files owned by apache2 user and group. Then you can start apache2 with the apache2 user:
3434

3535
```bash
36-
dosr systemctl start apache2
36+
sr systemctl start apache2
3737
```

0 commit comments

Comments
 (0)