Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prototype for adding user modes
Browse files Browse the repository at this point in the history
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 <vsoch@users.noreply.github.com>
vsoch committed Jan 27, 2024
1 parent 5ff3b0a commit 6d8b4a0
Showing 6 changed files with 26 additions and 4 deletions.
7 changes: 7 additions & 0 deletions app/core/config.py
Original file line number Diff line number Diff line change
@@ -88,8 +88,15 @@ class Settings(BaseSettings):
db_file: str = "sqlite:///./flux-restful.db"
flux_user: str = os.environ.get("FLUX_USER") or "fluxuser"
flux_token: Optional[str] = os.environ.get("FLUX_TOKEN")
flux_server_mode: Optional[str] = (
os.environ.get("FLUX_SERVER_MODE") or "single-user"
)
secret_key: str = os.environ.get("FLUX_SECRET_KEY") or generate_secret_key()

# Validate the server mode provided.
if flux_server_mode not in ["single-user", "multi-user"]:
raise ValueError("FLUX_SERVER_MODE must be single-user or multi-user")

# Expires in 10 hours
access_token_expires_minutes: int = get_int_envar(
"FLUX_ACCESS_TOKEN_EXPIRES_MINUTES", 600
4 changes: 2 additions & 2 deletions app/library/flux.py
Original file line number Diff line number Diff line change
@@ -33,8 +33,8 @@ def submit_job(handle, fluxjob, user):
elif user and isinstance(user, str):
print(f"User submitting job {user}")

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

2 changes: 2 additions & 0 deletions clients/python/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -14,6 +14,8 @@ and **Merged pull requests**. Critical items to know are:
The versions coincide with releases on pip. Only major versions will be released as tags on Github.

## [0.0.x](https://github.com/flux-framework/flux-restful-api/tree/main) (0.0.x)
- Fix bug with submit and POST needing params (0.2.1)
- New release with updated client (0.2.0)
- Update to use newer versions of fastapi, etc (0.1.15)
- option_flags is a flat string list of values
- Expose host to environment and bug fix for logs (0.1.14)
2 changes: 1 addition & 1 deletion clients/python/flux_restful_client/main/client.py
Original file line number Diff line number Diff line change
@@ -278,7 +278,7 @@ def submit(self, command, **kwargs):

# Validate the data first.
jsonschema.validate(data, schema=schemas.job_submit_schema)
result = self.do_request("jobs/submit", "POST", data=data)
result = self.do_request("jobs/submit", "POST", json=data)
if result.status_code == 404:
print("There is no job for that identifier.")
return
2 changes: 1 addition & 1 deletion clients/python/flux_restful_client/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.2.0"
__version__ = "0.2.1"
AUTHOR = "Vanessa Sochat"
EMAIL = "vsoch@users.noreply.github.com"
NAME = "flux-restful-client"
13 changes: 13 additions & 0 deletions docs/getting_started/user-guide.md
Original file line number Diff line number Diff line change
@@ -17,6 +17,19 @@ There are two modes of interaction:
- **multi-user mode**: requires authentication via the RESTful API with an encoded payload to request expiring tokens. When authentication is successful, the
job is run as the same user on the system on behalf of the flux user.

To control the user mode, you can export it to the environment where you are running the server:

```bash
# This is the default
export FLUX_SERVER_MODE=single-user

# This will have the flux user attempt to sign the payload with sudo
export FLUX_SERVER_MODE=multi-user
```

Note that the majority of our use cases use single-user mode, so you can expect more bugs / work to be
done with multi-user.

### Authentication

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

0 comments on commit 6d8b4a0

Please sign in to comment.