rda-python-setuid 1.0.7__tar.gz → 1.0.9__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.7/src/rda_python_setuid.egg-info → rda_python_setuid-1.0.9}/PKG-INFO +8 -8
  2. {rda_python_setuid-1.0.7 → rda_python_setuid-1.0.9}/README.md +7 -7
  3. {rda_python_setuid-1.0.7 → rda_python_setuid-1.0.9}/pyproject.toml +1 -1
  4. {rda_python_setuid-1.0.7 → rda_python_setuid-1.0.9}/src/rda_python_setuid/install.py +23 -18
  5. {rda_python_setuid-1.0.7 → rda_python_setuid-1.0.9}/src/rda_python_setuid/install.usg +25 -16
  6. {rda_python_setuid-1.0.7 → rda_python_setuid-1.0.9}/src/rda_python_setuid/pgstart.py +1 -1
  7. {rda_python_setuid-1.0.7 → rda_python_setuid-1.0.9}/src/rda_python_setuid/pywrapper.c +3 -3
  8. {rda_python_setuid-1.0.7 → rda_python_setuid-1.0.9/src/rda_python_setuid.egg-info}/PKG-INFO +8 -8
  9. {rda_python_setuid-1.0.7 → rda_python_setuid-1.0.9}/LICENSE +0 -0
  10. {rda_python_setuid-1.0.7 → rda_python_setuid-1.0.9}/MANIFEST.in +0 -0
  11. {rda_python_setuid-1.0.7 → rda_python_setuid-1.0.9}/setup.cfg +0 -0
  12. {rda_python_setuid-1.0.7 → rda_python_setuid-1.0.9}/src/rda_python_setuid/__init__.py +0 -0
  13. {rda_python_setuid-1.0.7 → rda_python_setuid-1.0.9}/src/rda_python_setuid/pywrapper.py +0 -0
  14. {rda_python_setuid-1.0.7 → rda_python_setuid-1.0.9}/src/rda_python_setuid.egg-info/SOURCES.txt +0 -0
  15. {rda_python_setuid-1.0.7 → rda_python_setuid-1.0.9}/src/rda_python_setuid.egg-info/dependency_links.txt +0 -0
  16. {rda_python_setuid-1.0.7 → rda_python_setuid-1.0.9}/src/rda_python_setuid.egg-info/entry_points.txt +0 -0
  17. {rda_python_setuid-1.0.7 → rda_python_setuid-1.0.9}/src/rda_python_setuid.egg-info/requires.txt +0 -0
  18. {rda_python_setuid-1.0.7 → rda_python_setuid-1.0.9}/src/rda_python_setuid.egg-info/top_level.txt +0 -0
  19. {rda_python_setuid-1.0.7 → rda_python_setuid-1.0.9}/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.7
3
+ Version: 1.0.9
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
@@ -74,8 +74,9 @@ prefix:
74
74
  ```
75
75
 
76
76
  `pip install` then places `setuid_dsarch` in the environment's `bin/` directory
77
- automatically. `pywrapper-install -l/--link` locks it down to `chmod 700` so users
78
- cannot bypass the setuid wrapper by running it directly.
77
+ automatically. `pywrapper-install -l/--link` creates the symlink
78
+ `dsarch -> pywrapper`; running `dsarch` goes through the setuid wrapper, which
79
+ execs `setuid_dsarch` as CommonUser.
79
80
 
80
81
  ## Environment setup
81
82
 
@@ -113,13 +114,13 @@ pywrapper-install
113
114
  pip install rda_python_dsarch
114
115
 
115
116
  # 2. Compile pywrapper C binary (once per environment):
116
- pywrapper-install
117
+ pywrapper-install -c|--compile
117
118
 
118
119
  # 3. Wire up each program as a setuid entry:
119
- pywrapper-install -l dsarch
120
+ pywrapper-install -l|--link dsarch
120
121
 
121
122
  # 4. Optionally, allow a specialist to run commands as themselves:
122
- pywrapper-install -p -u zji
123
+ pywrapper-install -p|--pgstart -u|--user zji
123
124
  ```
124
125
 
125
126
  ### Simple install (no sudo required, runs as current user)
@@ -129,7 +130,7 @@ direct symlink from `dsarch` to `setuid_dsarch`:
129
130
 
130
131
  ```bash
131
132
  pip install rda_python_dsarch
132
- pywrapper-install -l dsarch -s
133
+ pywrapper-install -l|--link dsarch -s|--simple
133
134
  ```
134
135
 
135
136
  ## Runtime flow
@@ -138,7 +139,6 @@ pywrapper-install -l dsarch -s
138
139
  user runs: dsarch [args]
139
140
  | (symlink -> pywrapper, setuid bit -> EUID=gdexdata)
140
141
  pywrapper.c: execv(bin/setuid_dsarch, args)
141
- | (chmod 700, only gdexdata can exec directly)
142
142
  setuid_dsarch: calls dsarch:main() as gdexdata
143
143
  ```
144
144
 
@@ -58,8 +58,9 @@ prefix:
58
58
  ```
59
59
 
60
60
  `pip install` then places `setuid_dsarch` in the environment's `bin/` directory
61
- automatically. `pywrapper-install -l/--link` locks it down to `chmod 700` so users
62
- cannot bypass the setuid wrapper by running it directly.
61
+ automatically. `pywrapper-install -l/--link` creates the symlink
62
+ `dsarch -> pywrapper`; running `dsarch` goes through the setuid wrapper, which
63
+ execs `setuid_dsarch` as CommonUser.
63
64
 
64
65
  ## Environment setup
65
66
 
@@ -97,13 +98,13 @@ pywrapper-install
97
98
  pip install rda_python_dsarch
98
99
 
99
100
  # 2. Compile pywrapper C binary (once per environment):
100
- pywrapper-install
101
+ pywrapper-install -c|--compile
101
102
 
102
103
  # 3. Wire up each program as a setuid entry:
103
- pywrapper-install -l dsarch
104
+ pywrapper-install -l|--link dsarch
104
105
 
105
106
  # 4. Optionally, allow a specialist to run commands as themselves:
106
- pywrapper-install -p -u zji
107
+ pywrapper-install -p|--pgstart -u|--user zji
107
108
  ```
108
109
 
109
110
  ### Simple install (no sudo required, runs as current user)
@@ -113,7 +114,7 @@ direct symlink from `dsarch` to `setuid_dsarch`:
113
114
 
114
115
  ```bash
115
116
  pip install rda_python_dsarch
116
- pywrapper-install -l dsarch -s
117
+ pywrapper-install -l|--link dsarch -s|--simple
117
118
  ```
118
119
 
119
120
  ## Runtime flow
@@ -122,7 +123,6 @@ pywrapper-install -l dsarch -s
122
123
  user runs: dsarch [args]
123
124
  | (symlink -> pywrapper, setuid bit -> EUID=gdexdata)
124
125
  pywrapper.c: execv(bin/setuid_dsarch, args)
125
- | (chmod 700, only gdexdata can exec directly)
126
126
  setuid_dsarch: calls dsarch:main() as gdexdata
127
127
  ```
128
128
 
@@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
6
6
 
7
7
  [project]
8
8
  name = "rda_python_setuid"
9
- version = "1.0.7"
9
+ version = "1.0.9"
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]
@@ -28,8 +31,9 @@
28
31
  # [project.scripts]
29
32
  # "setuid_dsarch" = "rda_python_dsarch.dsarch:main"
30
33
  # pip install places setuid_dsarch in the bin dir automatically.
31
- # pywrapper-install --link dsarch will chown setuid_dsarch to CommonUser and
32
- # chmod 700, so users cannot run it directly and must go through the setuid wrapper.
34
+ # pywrapper-install --link dsarch creates the symlink dsarch -> pywrapper, so
35
+ # users invoking dsarch go through the setuid wrapper which execs setuid_dsarch
36
+ # as CommonUser.
33
37
  # pywrapper-install --link dsarch --simple creates dsarch -> setuid_dsarch directly,
34
38
  # skipping setuid; the program runs as the current user.
35
39
  #
@@ -65,9 +69,6 @@ def show_usage():
65
69
 
66
70
  def main():
67
71
 
68
- if len(sys.argv) == 1:
69
- show_usage()
70
-
71
72
  parser = argparse.ArgumentParser(
72
73
  description="Compile and install the pywrapper setuid C binary."
73
74
  )
@@ -84,6 +85,10 @@ def main():
84
85
  help="Simple install: create symlink PROGRAM -> setuid_PROGRAM, skipping setuid (use with -l/--link)"
85
86
  )
86
87
  group = parser.add_mutually_exclusive_group()
88
+ group.add_argument(
89
+ '-c', '--compile', action='store_true',
90
+ help="Compile pywrapper.c and install bin/pywrapper as a setuid binary (run once per environment)"
91
+ )
87
92
  group.add_argument(
88
93
  '-p', '--pgstart', action='store_true',
89
94
  help="Create pgstart_USER for running commands as USER (Mode 2)"
@@ -94,6 +99,9 @@ def main():
94
99
  )
95
100
  args = parser.parse_args()
96
101
 
102
+ if not (args.compile or args.pgstart or args.link):
103
+ show_usage()
104
+
97
105
  if args.user is None and not args.simple:
98
106
  import pwd
99
107
  if args.pgstart:
@@ -118,19 +126,13 @@ def main():
118
126
  os.symlink(script, target)
119
127
  print("Created: {} -> setuid_{}".format(target, args.link))
120
128
  else:
121
- # Mode 1: symlink PROGRAM -> pywrapper, then lock down setuid_PROGRAM
122
- # so users cannot bypass the setuid wrapper by running it directly.
129
+ # Mode 1: symlink PROGRAM -> pywrapper. setuid_PROGRAM is left with its
130
+ # default ownership/permissions so it can be loaded and executed normally.
123
131
  if os.path.lexists(target):
124
132
  print("Already exists: {}".format(target))
125
133
  else:
126
134
  os.symlink(pywrapper, target)
127
135
  print("Created: {} -> pywrapper".format(target))
128
- # chown and chmod 700: only CommonUser can execute setuid_PROGRAM directly.
129
- # pywrapper (running as CommonUser via setuid) can still execv it, but any
130
- # direct invocation by other users will get "permission denied".
131
- run(['sudo', '-u', args.user, 'chown', args.user, script])
132
- run(['sudo', '-u', args.user, 'chmod', '700', script])
133
- print("Locked: {} (chmod 700, owned by {})".format(script, args.user))
134
136
 
135
137
  elif args.pgstart:
136
138
  # Mode 2: copy pywrapper to pgstart_USER with setuid owned by USER
@@ -138,12 +140,15 @@ def main():
138
140
  print("Error: {} not found. Run pywrapper-install --user COMMONUSER first.".format(pywrapper))
139
141
  sys.exit(1)
140
142
  target = os.path.join(bindir, 'pgstart_{}'.format(args.user))
141
- run(['sudo', '-u', args.user, 'cp', pywrapper, target])
142
- run(['sudo', '-u', args.user, 'chmod', '4750', target])
143
+ import pwd
144
+ curuser = pwd.getpwuid(os.getuid()).pw_name
145
+ sudo_prefix = [] if curuser == args.user else ['sudo', '-u', args.user]
146
+ run(sudo_prefix + ['cp', pywrapper, target])
147
+ run(sudo_prefix + ['chmod', '4750', target])
143
148
  print("Installed: {} (setuid, owned by {})".format(target, args.user))
144
149
 
145
- else:
146
- # Default: compile pywrapper.c and install pywrapper with setuid
150
+ elif args.compile:
151
+ # Compile pywrapper.c and install pywrapper with setuid
147
152
  src = get_c_source()
148
153
  src_dest = os.path.join(bindir, 'pywrapper.c')
149
154
  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,23 @@
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
- Mode 1: create a symlink PROGRAM -> pywrapper in the bin/ directory, then
26
- lock down setuid_PROGRAM (chmod 700, owned by USER) so users cannot bypass
27
- the setuid wrapper by running setuid_PROGRAM directly. Cannot be combined
28
- with -p/--pgstart.
38
+ Mode 1: create a symlink PROGRAM -> pywrapper in the bin/ directory so
39
+ that running PROGRAM invokes the setuid wrapper, which then execs
40
+ setuid_PROGRAM as CommonUser. setuid_PROGRAM keeps its default
41
+ ownership and permissions. Cannot be combined with -c/--compile or
42
+ -p/--pgstart.
29
43
 
30
44
  - Option -s or --simple (use with -l/--link)
31
45
  Simple install: create a symlink PROGRAM -> setuid_PROGRAM directly,
@@ -33,11 +47,6 @@
33
47
  user with no privilege change. -u/--user is not required with this option.
34
48
  Useful for users who do not need or cannot set up the setuid wrapper.
35
49
 
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
50
  Convention for wrapped programs:
42
51
  Any Python package whose program is to be run via pywrapper must:
43
52
 
@@ -58,8 +67,8 @@
58
67
  "setuid_dsarch" = "rda_python_dsarch.dsarch:main"
59
68
 
60
69
  pip install then places setuid_dsarch in the bin/ directory automatically.
61
- Running pywrapper-install --link will lock it down (chmod 700) so that only
62
- pywrapper (running as CommonUser via its setuid bit) can execv it.
70
+ Running pywrapper-install --link creates the symlink dsarch -> pywrapper;
71
+ pywrapper (running as CommonUser via its setuid bit) execs setuid_dsarch.
63
72
 
64
73
  Environment Setup:
65
74
 
@@ -99,7 +108,7 @@
99
108
  pip install rda_python_dsarch
100
109
 
101
110
  2. Compile pywrapper (once per environment):
102
- pywrapper-install
111
+ pywrapper-install -c
103
112
 
104
113
  3. Wire up each program as a setuid entry:
105
114
  pywrapper-install -l dsarch
@@ -118,10 +127,10 @@
118
127
  Examples:
119
128
 
120
129
  1. Compile and install pywrapper for common user gdexdata (default):
121
- pywrapper-install
130
+ pywrapper-install -c
122
131
 
123
132
  2. Same, but targeting a specific environment:
124
- pywrapper-install -e /glade/u/home/gdexdata/gdexmsenv
133
+ pywrapper-install -c -e /glade/u/home/gdexdata/gdexmsenv
125
134
 
126
135
  3. Wire up dsarch to run as gdexdata via pywrapper:
127
136
  pywrapper-install -l dsarch
@@ -49,7 +49,7 @@ def main():
49
49
  euid = pglog.PGLOG['EUID']
50
50
  ruser = pwd.getpwuid(ruid).pw_name
51
51
  euser = pwd.getpwuid(euid).pw_name
52
- if ruser == euser or ruser == pglog.PGLOG['GDEXUSER']: permit = True
52
+ if ruser == euser or ruser == pglog.PGLOG['GDEXUSER'] or euser == pglog.PGLOG['GDEXUSER']: permit = True
53
53
  pglog.set_suid(euid)
54
54
 
55
55
  while argv:
@@ -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.7
3
+ Version: 1.0.9
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
@@ -74,8 +74,9 @@ prefix:
74
74
  ```
75
75
 
76
76
  `pip install` then places `setuid_dsarch` in the environment's `bin/` directory
77
- automatically. `pywrapper-install -l/--link` locks it down to `chmod 700` so users
78
- cannot bypass the setuid wrapper by running it directly.
77
+ automatically. `pywrapper-install -l/--link` creates the symlink
78
+ `dsarch -> pywrapper`; running `dsarch` goes through the setuid wrapper, which
79
+ execs `setuid_dsarch` as CommonUser.
79
80
 
80
81
  ## Environment setup
81
82
 
@@ -113,13 +114,13 @@ pywrapper-install
113
114
  pip install rda_python_dsarch
114
115
 
115
116
  # 2. Compile pywrapper C binary (once per environment):
116
- pywrapper-install
117
+ pywrapper-install -c|--compile
117
118
 
118
119
  # 3. Wire up each program as a setuid entry:
119
- pywrapper-install -l dsarch
120
+ pywrapper-install -l|--link dsarch
120
121
 
121
122
  # 4. Optionally, allow a specialist to run commands as themselves:
122
- pywrapper-install -p -u zji
123
+ pywrapper-install -p|--pgstart -u|--user zji
123
124
  ```
124
125
 
125
126
  ### Simple install (no sudo required, runs as current user)
@@ -129,7 +130,7 @@ direct symlink from `dsarch` to `setuid_dsarch`:
129
130
 
130
131
  ```bash
131
132
  pip install rda_python_dsarch
132
- pywrapper-install -l dsarch -s
133
+ pywrapper-install -l|--link dsarch -s|--simple
133
134
  ```
134
135
 
135
136
  ## Runtime flow
@@ -138,7 +139,6 @@ pywrapper-install -l dsarch -s
138
139
  user runs: dsarch [args]
139
140
  | (symlink -> pywrapper, setuid bit -> EUID=gdexdata)
140
141
  pywrapper.c: execv(bin/setuid_dsarch, args)
141
- | (chmod 700, only gdexdata can exec directly)
142
142
  setuid_dsarch: calls dsarch:main() as gdexdata
143
143
  ```
144
144