PSI_K API
This project presents a REST-HTTP API to PSI_K, a portable batch job submission interface.
To setup and run:
- Install the rc shell and psik_api (from the site you intend to use):
module load python/3
python3 -m venv
getrc.sh venv # https://github.com/frobnitzem/rcrc
VIRTUAL_ENV=/full/path/to/venv
PATH=$VIRTUAL_ENV/bin:$PATH
pip install git+https://github.com/frobnitzem/psik_api.git
-
Setup a psik_api config file. This file is a key-value store mapping machine names to psik config files -- one for each scheduler configuration.
Be careful with the
psik_pathandrc_pathoptions here. These paths must be accessible during the execution of the job, and on the host running psik_api.Note that the
PSIK_CONFIGenvironment variable does not influence the server runningpsik_api.Create a config file at
$PSIK_API_CONFIG(defaults to$VIRTUAL_ENV/etc/psik_api.json) like,{ "backends": { "default": { "prefix": "/tmp/psik_jobs", "backend": { "type": "local"} } } }or
{ "backends": { "default": { "prefix": "/ccs/proj/prj123/uname/frontier", "psik_path": "/ccs/proj/prj123/uname/frontier/bin/psik", "rc_path": "/ccs/proj/prj123/uname/frontier/bin/rc", "backend": { "type": "slurm", "project_name": "prj123", "attributes": { "---gpu-bind": "closest" } } } } } -
Start the server. This can be done either directly by ssh-tunneling to a login node, or indirectly by starting a long-running containerized service.
The ssh-tunnel method is simplest,
ssh frontier -L 127.0.0.1:8000:/ccs/home/uname/psik_api.sock
activate /ccs/proj/prj123/frontier
uvicorn psik_api.main:app --log-level info --uds $HOME/psik_api.sock
Note that using a UNIX socket in `$HOME` is secure as long as
only your user can read/write from it.
For a more secure environment, use the `certified` package with:
ssh frontier -L 8000:localhost:4433
activate /ccs/proj/prj123/frontier
certified serve psik_api.main:app https://127.0.0.1:4433
`certified` is a dependency of psik_api, so should already
be available if you have installed psik.
- Browse / access the API at:
http://127.0.0.1:8000/
- Send a test job:
curl -X POST \
http://127.0.0.1:8000/v1/jobs \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"name": "show system info",
"script": "cat /proc/cpuinfo; cat /proc/meminfo; rocm-smi; echo $nodes; $mpirun hostname",
"resources": {
"process_count": 8,
"cpu_cores_per_process": 7,
"duration": 2,
"gpu_cores_per_process": 1
}
}'
curl -X GET \
'http://127.0.0.1:8000/v1/jobs \
-H 'accept: application/json'
# replace 1693992878.203 with your job's jobid
curl -X GET \
'http://127.0.0.1:8000/v1/jobs/1693992878.203/logs' \
-H 'accept: application/json'
- Create a job without submitting it, then send input files, then submit
# full JobSpec must be present at this point,
# but it will not run until later
curl -X POST \
http://127.0.0.1:8000/v1/jobs/new \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"script": "cat data.txt",
}'
# replace 1693992878.203 with your job's jobid below
# Upload files
curl -X POST \
'http://127.0.0.1:8000/v1/jobs/1693992878.203/files/ \
-H 'accept: application/json' \
--upload-file data.txt
# start the job
curl -X POST \
'http://127.0.0.1:8000/v1/jobs/1693992878.203/start' \
-H 'accept: application/json'
Authorization and Authentication
The server has 3 modes of operation:
-
local -- when specifically requested with configuration setting "authz"="local". In this mode, only requests originating from the localhost IP (either v4 or v6) will be served. Also, this mode is the only way to serve the full API through a UNIX domain socket.
-
insecure -- when Request.transport is not available (started without certified serve). In this case the user name is taken as 'addr:' -- based on the client's address. Psik_api will refuse to issue tokens (hence no access to secured routes) in this case.
-
TLS -- when started with
certified serve
In local mode, the system sees all jobs as owned by user
local:psik_api.
In TLS mode, the user value is read from a biscuit
token that the client provides on each request.
This should be present in a header like,
Authorization: bearer b64-encoded-biscuit-value=.
If no biscuit is provided with the request, then one is
auto-generated for that request by reading the client's
TLS certificate.
Note, a biscuit can also be generated with user == client
by visiting the /token endpoint.
A database tracks the owner of each job and grants GET/POST permissions only to a job's owner. This way, a user can delegate access permissions to a job to another user or an automated agent.
Note that biscuits allow tokens to be attenuated by enforcing additional checks. For example, by checking mode=GET, they can confer a token that grants read-only access.
Sites may customize the job access policy above by
implementing a custom authz class -- replacing
psik_api.authz:BaseAuthz in their Config.authz
setting.
Metadata
Release files for psik_api 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| psik_api-1.0.0.tar.gz | 15.2 kB | Without provenance | Details for psik_api-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| psik_api-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for psik_api-1.0.0-py3-none-any.whl |
Total release size: 32.8 kB
Release files / psik_api-1.0.0.tar.gz
| Download URL | psik_api-1.0.0.tar.gz |
|---|---|
| Size | 15.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4bdacd803df30759166c68f138bfe57e92c882f09136f1b436c6912c936f74fe
|
|
BLAKE2b-256 checksum How to use checksums |
50b3b0472a941e99b7ea27b5b59ccf5c6a2d53aa64e848416c24c392ef63f278
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.1 CPython/3.10.12 Linux/6.8.0-47-generic
|
Release files / psik_api-1.0.0-py3-none-any.whl
| Download URL | psik_api-1.0.0-py3-none-any.whl |
|---|---|
| Size | 17.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5d8ad6786c945755c06cadeb159e7cb31f90111f85f756f49c3290088743f3c0
|
|
BLAKE2b-256 checksum How to use checksums |
b76b7f1a35cb45bf24b8885d10d12b1247767e7c0123842aa9b21b32228a5464
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.1 CPython/3.10.12 Linux/6.8.0-47-generic
|
Security for psik_api 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.