rda-python-setuid 1.0.6__tar.gz → 1.0.8__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (19) hide show
  1. {rda_python_setuid-1.0.6/src/rda_python_setuid.egg-info → rda_python_setuid-1.0.8}/PKG-INFO +27 -5
  2. {rda_python_setuid-1.0.6 → rda_python_setuid-1.0.8}/README.md +26 -4
  3. {rda_python_setuid-1.0.6 → rda_python_setuid-1.0.8}/pyproject.toml +1 -1
  4. {rda_python_setuid-1.0.6 → rda_python_setuid-1.0.8}/src/rda_python_setuid/install.py +13 -6
  5. {rda_python_setuid-1.0.6 → rda_python_setuid-1.0.8}/src/rda_python_setuid/install.usg +19 -11
  6. {rda_python_setuid-1.0.6 → rda_python_setuid-1.0.8}/src/rda_python_setuid/pywrapper.c +3 -3
  7. {rda_python_setuid-1.0.6 → rda_python_setuid-1.0.8/src/rda_python_setuid.egg-info}/PKG-INFO +27 -5
  8. {rda_python_setuid-1.0.6 → rda_python_setuid-1.0.8}/LICENSE +0 -0
  9. {rda_python_setuid-1.0.6 → rda_python_setuid-1.0.8}/MANIFEST.in +0 -0
  10. {rda_python_setuid-1.0.6 → rda_python_setuid-1.0.8}/setup.cfg +0 -0
  11. {rda_python_setuid-1.0.6 → rda_python_setuid-1.0.8}/src/rda_python_setuid/__init__.py +0 -0
  12. {rda_python_setuid-1.0.6 → rda_python_setuid-1.0.8}/src/rda_python_setuid/pgstart.py +0 -0
  13. {rda_python_setuid-1.0.6 → rda_python_setuid-1.0.8}/src/rda_python_setuid/pywrapper.py +0 -0
  14. {rda_python_setuid-1.0.6 → rda_python_setuid-1.0.8}/src/rda_python_setuid.egg-info/SOURCES.txt +0 -0
  15. {rda_python_setuid-1.0.6 → rda_python_setuid-1.0.8}/src/rda_python_setuid.egg-info/dependency_links.txt +0 -0
  16. {rda_python_setuid-1.0.6 → rda_python_setuid-1.0.8}/src/rda_python_setuid.egg-info/entry_points.txt +0 -0
  17. {rda_python_setuid-1.0.6 → rda_python_setuid-1.0.8}/src/rda_python_setuid.egg-info/requires.txt +0 -0
  18. {rda_python_setuid-1.0.6 → rda_python_setuid-1.0.8}/src/rda_python_setuid.egg-info/top_level.txt +0 -0
  19. {rda_python_setuid-1.0.6 → rda_python_setuid-1.0.8}/tests/test_setuid.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rda_python_setuid
3
- Version: 1.0.6
3
+ Version: 1.0.8
4
4
  Summary: RDA Python Package to setuid for program executions as an effective or common user
5
5
  Author-email: Zaihua Ji <zji@ucar.edu>
6
6
  Project-URL: Homepage, https://github.com/NCAR/rda-python-setuid
@@ -30,6 +30,28 @@ Two modes are supported:
30
30
  - **Mode 2 (pgstart specialist):** a copy `pgstart_zji` runs any command as specialist
31
31
  `zji` via `pgstart.py`, restricted to authorized users.
32
32
 
33
+ Two Python entry points are packaged alongside the C wrapper:
34
+
35
+ - **`pywrapper.py`** — the default fallback target executed when `pywrapper.c`
36
+ cannot resolve a matching `setuid_<program>` entry point. Acquires the
37
+ effective UID via `PgLOG.set_suid()`, prints the caller's real and effective
38
+ user names, and shows the `pyproject.toml` snippet plus the
39
+ `pywrapper-install -l <program>` command needed to wrap a new script.
40
+ Diagnostic flags `-env`, `-inc`, and `-plg` dump the environment variables,
41
+ `sys.path`, and `PGLOG` dictionary respectively — handy for verifying the
42
+ setuid environment before wiring up a real program.
43
+
44
+ - **`pgstart.py`** — the Mode 2 launcher invoked through a `pgstart_<USER>`
45
+ copy of `pywrapper`. Reads the real/effective UIDs from `PGLOG`, then
46
+ permits execution only if the real user matches the effective user or the
47
+ shared GDEX common user (`PGLOG['GDEXUSER']`); unauthorized callers receive
48
+ an informational message and exit. After authorization it parses leading
49
+ flag tokens — `-bg` (background via `subprocess.Popen`), `-fg` (explicit
50
+ foreground, default), `-cwd <dir>` (chdir before exec), and the same
51
+ `-env`/`-inc`/`-plg` diagnostics as `pywrapper.py` — and then runs the
52
+ remaining arguments as a command (`subprocess.run`/`Popen`) under the
53
+ effective UID, logging a host/program/timestamp/user line to `pgstart.log`.
54
+
33
55
  ## Dependency requirement
34
56
 
35
57
  Any Python package whose programs are to be run via the setuid mechanism must declare
@@ -91,13 +113,13 @@ pywrapper-install
91
113
  pip install rda_python_dsarch
92
114
 
93
115
  # 2. Compile pywrapper C binary (once per environment):
94
- pywrapper-install
116
+ pywrapper-install -c|--compile
95
117
 
96
118
  # 3. Wire up each program as a setuid entry:
97
- pywrapper-install -l dsarch
119
+ pywrapper-install -l|--link dsarch
98
120
 
99
121
  # 4. Optionally, allow a specialist to run commands as themselves:
100
- pywrapper-install -p -u zji
122
+ pywrapper-install -p|--pgstart -u|--user zji
101
123
  ```
102
124
 
103
125
  ### Simple install (no sudo required, runs as current user)
@@ -107,7 +129,7 @@ direct symlink from `dsarch` to `setuid_dsarch`:
107
129
 
108
130
  ```bash
109
131
  pip install rda_python_dsarch
110
- pywrapper-install -l dsarch -s
132
+ pywrapper-install -l|--link dsarch -s|--simple
111
133
  ```
112
134
 
113
135
  ## Runtime flow
@@ -14,6 +14,28 @@ Two modes are supported:
14
14
  - **Mode 2 (pgstart specialist):** a copy `pgstart_zji` runs any command as specialist
15
15
  `zji` via `pgstart.py`, restricted to authorized users.
16
16
 
17
+ Two Python entry points are packaged alongside the C wrapper:
18
+
19
+ - **`pywrapper.py`** — the default fallback target executed when `pywrapper.c`
20
+ cannot resolve a matching `setuid_<program>` entry point. Acquires the
21
+ effective UID via `PgLOG.set_suid()`, prints the caller's real and effective
22
+ user names, and shows the `pyproject.toml` snippet plus the
23
+ `pywrapper-install -l <program>` command needed to wrap a new script.
24
+ Diagnostic flags `-env`, `-inc`, and `-plg` dump the environment variables,
25
+ `sys.path`, and `PGLOG` dictionary respectively — handy for verifying the
26
+ setuid environment before wiring up a real program.
27
+
28
+ - **`pgstart.py`** — the Mode 2 launcher invoked through a `pgstart_<USER>`
29
+ copy of `pywrapper`. Reads the real/effective UIDs from `PGLOG`, then
30
+ permits execution only if the real user matches the effective user or the
31
+ shared GDEX common user (`PGLOG['GDEXUSER']`); unauthorized callers receive
32
+ an informational message and exit. After authorization it parses leading
33
+ flag tokens — `-bg` (background via `subprocess.Popen`), `-fg` (explicit
34
+ foreground, default), `-cwd <dir>` (chdir before exec), and the same
35
+ `-env`/`-inc`/`-plg` diagnostics as `pywrapper.py` — and then runs the
36
+ remaining arguments as a command (`subprocess.run`/`Popen`) under the
37
+ effective UID, logging a host/program/timestamp/user line to `pgstart.log`.
38
+
17
39
  ## Dependency requirement
18
40
 
19
41
  Any Python package whose programs are to be run via the setuid mechanism must declare
@@ -75,13 +97,13 @@ pywrapper-install
75
97
  pip install rda_python_dsarch
76
98
 
77
99
  # 2. Compile pywrapper C binary (once per environment):
78
- pywrapper-install
100
+ pywrapper-install -c|--compile
79
101
 
80
102
  # 3. Wire up each program as a setuid entry:
81
- pywrapper-install -l dsarch
103
+ pywrapper-install -l|--link dsarch
82
104
 
83
105
  # 4. Optionally, allow a specialist to run commands as themselves:
84
- pywrapper-install -p -u zji
106
+ pywrapper-install -p|--pgstart -u|--user zji
85
107
  ```
86
108
 
87
109
  ### Simple install (no sudo required, runs as current user)
@@ -91,7 +113,7 @@ direct symlink from `dsarch` to `setuid_dsarch`:
91
113
 
92
114
  ```bash
93
115
  pip install rda_python_dsarch
94
- pywrapper-install -l dsarch -s
116
+ pywrapper-install -l|--link dsarch -s|--simple
95
117
  ```
96
118
 
97
119
  ## Runtime flow
@@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
6
6
 
7
7
  [project]
8
8
  name = "rda_python_setuid"
9
- version = "1.0.6"
9
+ version = "1.0.8"
10
10
  authors = [
11
11
  { name="Zaihua Ji", email="zji@ucar.edu" },
12
12
  ]
@@ -11,8 +11,11 @@
11
11
  # Github: https://github.com/NCAR/rda-python-setuid.git
12
12
  #
13
13
  # Usage:
14
+ # # 0. Display this user guide:
15
+ # pywrapper-install
16
+ #
14
17
  # # 1. Compile and install pywrapper (run once per environment):
15
- # pywrapper-install [-u gdexdata] [-e $ENVHOME]
18
+ # pywrapper-install -c [-u gdexdata] [-e $ENVHOME]
16
19
  #
17
20
  # # 2. Create pgstart_USER entry so USER can run commands as themselves:
18
21
  # pywrapper-install -p [-u zji] [-e $ENVHOME]
@@ -65,9 +68,6 @@ def show_usage():
65
68
 
66
69
  def main():
67
70
 
68
- if len(sys.argv) == 1:
69
- show_usage()
70
-
71
71
  parser = argparse.ArgumentParser(
72
72
  description="Compile and install the pywrapper setuid C binary."
73
73
  )
@@ -84,6 +84,10 @@ def main():
84
84
  help="Simple install: create symlink PROGRAM -> setuid_PROGRAM, skipping setuid (use with -l/--link)"
85
85
  )
86
86
  group = parser.add_mutually_exclusive_group()
87
+ group.add_argument(
88
+ '-c', '--compile', action='store_true',
89
+ help="Compile pywrapper.c and install bin/pywrapper as a setuid binary (run once per environment)"
90
+ )
87
91
  group.add_argument(
88
92
  '-p', '--pgstart', action='store_true',
89
93
  help="Create pgstart_USER for running commands as USER (Mode 2)"
@@ -94,6 +98,9 @@ def main():
94
98
  )
95
99
  args = parser.parse_args()
96
100
 
101
+ if not (args.compile or args.pgstart or args.link):
102
+ show_usage()
103
+
97
104
  if args.user is None and not args.simple:
98
105
  import pwd
99
106
  if args.pgstart:
@@ -142,8 +149,8 @@ def main():
142
149
  run(['sudo', '-u', args.user, 'chmod', '4750', target])
143
150
  print("Installed: {} (setuid, owned by {})".format(target, args.user))
144
151
 
145
- else:
146
- # Default: compile pywrapper.c and install pywrapper with setuid
152
+ elif args.compile:
153
+ # Compile pywrapper.c and install pywrapper with setuid
147
154
  src = get_c_source()
148
155
  src_dest = os.path.join(bindir, 'pywrapper.c')
149
156
  shutil.copy(src, src_dest)
@@ -2,7 +2,14 @@
2
2
  that execute Python scripts as a common or effective user via the setuid mechanism.
3
3
  Must be run inside the target Python virtual environment.
4
4
 
5
- Usage: pywrapper-install [-u USER] [-e ENVHOME] [-p | -l PROGRAM [-s]]
5
+ Usage: pywrapper-install [-u|--user USER] [-e|--envhome ENVHOME]
6
+ ( -c|--compile
7
+ | -p|--pgstart
8
+ | -l|--link PROGRAM [-s|--simple] )
9
+
10
+ Run pywrapper-install with no arguments to display this user guide. Exactly
11
+ one of -c/--compile, -p/--pgstart, or -l/--link must be given to perform an
12
+ action.
6
13
 
7
14
  - Option -u or --user USER
8
15
  The user name to own the setuid binary. For Mode 1 (CommonUser program),
@@ -16,16 +23,22 @@
16
23
  Only needed when installing into an environment other than the one
17
24
  currently active.
18
25
 
26
+ - Option -c or --compile
27
+ Compile pywrapper.c (bundled with this package) and install it as
28
+ bin/pywrapper, owned by USER with chmod 4750 (setuid). Must be done
29
+ once per environment before using -p/--pgstart or -l/--link. Cannot
30
+ be combined with -p/--pgstart or -l/--link.
31
+
19
32
  - Option -p or --pgstart
20
33
  Mode 2: copy the compiled pywrapper binary to pgstart_USER (owned by USER,
21
34
  chmod 4750). Allows USER to run arbitrary commands as themselves via the
22
- setuid wrapper. Cannot be combined with -l/--link.
35
+ setuid wrapper. Cannot be combined with -c/--compile or -l/--link.
23
36
 
24
37
  - Option -l or --link PROGRAM
25
38
  Mode 1: create a symlink PROGRAM -> pywrapper in the bin/ directory, then
26
39
  lock down setuid_PROGRAM (chmod 700, owned by USER) so users cannot bypass
27
40
  the setuid wrapper by running setuid_PROGRAM directly. Cannot be combined
28
- with -p/--pgstart.
41
+ with -c/--compile or -p/--pgstart.
29
42
 
30
43
  - Option -s or --simple (use with -l/--link)
31
44
  Simple install: create a symlink PROGRAM -> setuid_PROGRAM directly,
@@ -33,11 +46,6 @@
33
46
  user with no privilege change. -u/--user is not required with this option.
34
47
  Useful for users who do not need or cannot set up the setuid wrapper.
35
48
 
36
- When run without --pgstart or --link, the default action is to compile pywrapper.c
37
- (bundled with this package) and install it as bin/pywrapper, owned by USER with
38
- chmod 4750 (setuid). This step must be done once per environment before using
39
- --pgstart or --link.
40
-
41
49
  Convention for wrapped programs:
42
50
  Any Python package whose program is to be run via pywrapper must:
43
51
 
@@ -99,7 +107,7 @@
99
107
  pip install rda_python_dsarch
100
108
 
101
109
  2. Compile pywrapper (once per environment):
102
- pywrapper-install
110
+ pywrapper-install -c
103
111
 
104
112
  3. Wire up each program as a setuid entry:
105
113
  pywrapper-install -l dsarch
@@ -118,10 +126,10 @@
118
126
  Examples:
119
127
 
120
128
  1. Compile and install pywrapper for common user gdexdata (default):
121
- pywrapper-install
129
+ pywrapper-install -c
122
130
 
123
131
  2. Same, but targeting a specific environment:
124
- pywrapper-install -e /glade/u/home/gdexdata/gdexmsenv
132
+ pywrapper-install -c -e /glade/u/home/gdexdata/gdexmsenv
125
133
 
126
134
  3. Wire up dsarch to run as gdexdata via pywrapper:
127
135
  pywrapper-install -l dsarch
@@ -10,15 +10,15 @@
10
10
  * python -m pip install rda_python_setuid
11
11
  *
12
12
  * # Compile pywrapper and set setuid bit (owned by CommonUser):
13
- * pywrapper-install [-u CommonUser] [-e $ENVHOME/bin]
13
+ * pywrapper-install -c|--compile [-u|--user CommonUser] [-e|--envhome $ENVHOME]
14
14
  *
15
15
  * # For an existing python program, $ENVHOME/bin/setuid_CommonProgram, to execute it
16
16
  * # as the common user (Mode 1 - symlink):
17
- * pywrapper-install -l CommonProgram [-u CommonUser] [-e $ENVHOME/bin]
17
+ * pywrapper-install -l|--link CommonProgram [-u|--user CommonUser] [-e|--envhome $ENVHOME]
18
18
  * CommonProgram [options]
19
19
  *
20
20
  * # For a specialist to run commands as themselves via pgstart (Mode 2):
21
- * pywrapper-install -p [-u EffectUser] [-e $ENVHOME/bin]
21
+ * pywrapper-install -p|--pgstart [-u|--user EffectUser] [-e|--envhome $ENVHOME]
22
22
  * pgstart_EffectUser EffectProgram [options]
23
23
  *
24
24
  * N: python 3 release number, it is 10 for Python 3.10.12
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rda_python_setuid
3
- Version: 1.0.6
3
+ Version: 1.0.8
4
4
  Summary: RDA Python Package to setuid for program executions as an effective or common user
5
5
  Author-email: Zaihua Ji <zji@ucar.edu>
6
6
  Project-URL: Homepage, https://github.com/NCAR/rda-python-setuid
@@ -30,6 +30,28 @@ Two modes are supported:
30
30
  - **Mode 2 (pgstart specialist):** a copy `pgstart_zji` runs any command as specialist
31
31
  `zji` via `pgstart.py`, restricted to authorized users.
32
32
 
33
+ Two Python entry points are packaged alongside the C wrapper:
34
+
35
+ - **`pywrapper.py`** — the default fallback target executed when `pywrapper.c`
36
+ cannot resolve a matching `setuid_<program>` entry point. Acquires the
37
+ effective UID via `PgLOG.set_suid()`, prints the caller's real and effective
38
+ user names, and shows the `pyproject.toml` snippet plus the
39
+ `pywrapper-install -l <program>` command needed to wrap a new script.
40
+ Diagnostic flags `-env`, `-inc`, and `-plg` dump the environment variables,
41
+ `sys.path`, and `PGLOG` dictionary respectively — handy for verifying the
42
+ setuid environment before wiring up a real program.
43
+
44
+ - **`pgstart.py`** — the Mode 2 launcher invoked through a `pgstart_<USER>`
45
+ copy of `pywrapper`. Reads the real/effective UIDs from `PGLOG`, then
46
+ permits execution only if the real user matches the effective user or the
47
+ shared GDEX common user (`PGLOG['GDEXUSER']`); unauthorized callers receive
48
+ an informational message and exit. After authorization it parses leading
49
+ flag tokens — `-bg` (background via `subprocess.Popen`), `-fg` (explicit
50
+ foreground, default), `-cwd <dir>` (chdir before exec), and the same
51
+ `-env`/`-inc`/`-plg` diagnostics as `pywrapper.py` — and then runs the
52
+ remaining arguments as a command (`subprocess.run`/`Popen`) under the
53
+ effective UID, logging a host/program/timestamp/user line to `pgstart.log`.
54
+
33
55
  ## Dependency requirement
34
56
 
35
57
  Any Python package whose programs are to be run via the setuid mechanism must declare
@@ -91,13 +113,13 @@ pywrapper-install
91
113
  pip install rda_python_dsarch
92
114
 
93
115
  # 2. Compile pywrapper C binary (once per environment):
94
- pywrapper-install
116
+ pywrapper-install -c|--compile
95
117
 
96
118
  # 3. Wire up each program as a setuid entry:
97
- pywrapper-install -l dsarch
119
+ pywrapper-install -l|--link dsarch
98
120
 
99
121
  # 4. Optionally, allow a specialist to run commands as themselves:
100
- pywrapper-install -p -u zji
122
+ pywrapper-install -p|--pgstart -u|--user zji
101
123
  ```
102
124
 
103
125
  ### Simple install (no sudo required, runs as current user)
@@ -107,7 +129,7 @@ direct symlink from `dsarch` to `setuid_dsarch`:
107
129
 
108
130
  ```bash
109
131
  pip install rda_python_dsarch
110
- pywrapper-install -l dsarch -s
132
+ pywrapper-install -l|--link dsarch -s|--simple
111
133
  ```
112
134
 
113
135
  ## Runtime flow