Skip to content

Commit addd2a0

Browse files
authored
[wip] prototype for adding user modes (#65)
* prototype for adding user modes We really just need to allow setting auth (to get to the server) with the kind of request that is done once you are authenticated. Right now, the two variables are tangled. With this setting we should be able to enable auth and still ask for single user mode, to be tested! Signed-off-by: vsoch <[email protected]>
1 parent 5ff3b0a commit addd2a0

File tree

8 files changed

+32
-7
lines changed

8 files changed

+32
-7
lines changed

app/core/config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,15 @@ class Settings(BaseSettings):
8888
db_file: str = "sqlite:///./flux-restful.db"
8989
flux_user: str = os.environ.get("FLUX_USER") or "fluxuser"
9090
flux_token: Optional[str] = os.environ.get("FLUX_TOKEN")
91+
flux_server_mode: Optional[str] = (
92+
os.environ.get("FLUX_SERVER_MODE") or "single-user"
93+
)
9194
secret_key: str = os.environ.get("FLUX_SECRET_KEY") or generate_secret_key()
9295

96+
# Validate the server mode provided.
97+
if flux_server_mode not in ["single-user", "multi-user"]:
98+
raise ValueError("FLUX_SERVER_MODE must be single-user or multi-user")
99+
93100
# Expires in 10 hours
94101
access_token_expires_minutes: int = get_int_envar(
95102
"FLUX_ACCESS_TOKEN_EXPIRES_MINUTES", 600

app/library/auth.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def not_authenticated(detail="Incorrect user or token."):
2323

2424
def alert_auth():
2525
print("🍓 Require auth: %s" % settings.require_auth)
26+
print("🍓 Server mode: %s" % settings.flux_server_mode)
2627
print(
2728
"🍓 Secret key %s" % ("*" * len(settings.secret_key))
2829
if settings.secret_key

app/library/flux.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ def submit_job(handle, fluxjob, user):
3333
elif user and isinstance(user, str):
3434
print(f"User submitting job {user}")
3535

36-
# If we don't have auth enabled, submit in single-user mode
37-
if not settings.require_auth:
36+
# If we don't have auth enabled or request is for single-user mode
37+
if not settings.require_auth or settings.flux_server_mode == "single-user":
3838
print("Submit in single-user mode.")
3939
return flux.job.submit_async(handle, fluxjob)
4040

clients/python/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ and **Merged pull requests**. Critical items to know are:
1414
The versions coincide with releases on pip. Only major versions will be released as tags on Github.
1515

1616
## [0.0.x](https://github.com/flux-framework/flux-restful-api/tree/main) (0.0.x)
17+
- Fix bug with submit and POST needing params (0.2.1)
18+
- New release with updated client (0.2.0)
1719
- Update to use newer versions of fastapi, etc (0.1.15)
1820
- option_flags is a flat string list of values
1921
- Expose host to environment and bug fix for logs (0.1.14)

clients/python/flux_restful_client/main/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,15 @@ def do_request(
104104

105105
headers = headers or self.headers
106106
url = f"{self.host}/{self.prefix}/{endpoint}"
107+
method = method.upper()
107108

108109
# Make the request and return to calling function, unless requires auth
109110
try:
110111
if method == "POST" and stream:
111112
response = self.session.stream(
112113
method, url, json=data, params=params, headers=headers
113114
)
114-
if method == "POST":
115+
elif method == "POST":
115116
response = self.session.post(url, params=data, headers=headers)
116117
elif method == "GET" and stream:
117118
response = self.session.stream(

clients/python/flux_restful_client/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.2.0"
1+
__version__ = "0.2.1"
22
AUTHOR = "Vanessa Sochat"
33
44
NAME = "flux-restful-client"

docs/getting_started/developer-guide.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ $ docker run --rm -it -p 5000:5000 ghcr.io/flux-framework/flux-restful-api
4545
```
4646
```console
4747
🍓 Require auth: True
48+
🍓 Server mode: single-user
4849
🍓 Secret key ***********
4950
🍓 Flux user: ********
5051
🍓 Flux token: *****
@@ -110,8 +111,8 @@ $ flux start uvicorn app.main:app --host=0.0.0.0 --port=5000
110111
Or do it separately (two commands):
111112

112113
```bash
113-
$ flux start --test-size=4
114-
$ uvicorn app.main:app --host=0.0.0.0 --port=5000
114+
flux start --test-size=4
115+
uvicorn app.main:app --host=0.0.0.0 --port=5000
115116
```
116117

117118
For the latter, you can also use the Makefile:
@@ -195,7 +196,7 @@ The following variables are available (with their defaults):
195196
|FLUX_TOKEN| The token password to require for Basic Auth (if `FLUX_REQUIRE_AUTH` is set) | unset |
196197
|FLUX_USER| The username to require for Basic Auth (if `FLUX_REQUIRE_AUTH` is set) | unset |
197198
|FLUX_HAS_GPU | GPUs are available for the user to request | unset |
198-
|FLUX_NUMBER_NODES| The number of nodes available in the cluster | 1 |
199+
|FLUX_NUMBER_NODES| The number of nodes available (exposed) in the cluster | 1 |
199200
|FLUX_OPTION_FLAGS | Option flags to give to flux, in the same format you'd give on the command line | unset |
200201
|FLUX_SECRET_KEY | secret key to be shared between user and server (required) | unset |
201202
|FLUX_ACCESS_TOKEN_EXPIRES_MINUTES| number of minutes to expire an access token | 600 |

docs/getting_started/user-guide.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@ There are two modes of interaction:
1717
- **multi-user mode**: requires authentication via the RESTful API with an encoded payload to request expiring tokens. When authentication is successful, the
1818
job is run as the same user on the system on behalf of the flux user.
1919

20+
To control the user mode, you can export it to the environment where you are running the server:
21+
22+
```bash
23+
# This is the default
24+
export FLUX_SERVER_MODE=single-user
25+
26+
# This will have the flux user attempt to sign the payload with sudo
27+
export FLUX_SERVER_MODE=multi-user
28+
```
29+
30+
Note that the majority of our use cases use single-user mode, so you can expect more bugs / work to be
31+
done with multi-user.
32+
2033
### Authentication
2134

2235
If you choose to deploy without authentication, this is a ⚠️ proceed at your own risk ⚠️ sort of deal.

0 commit comments

Comments
 (0)