Metadata-Version: 2.4
Name: raz_client_jwt_auth
Version: 1.0.0
Summary: boto3 plugin for S3 Ranger authorization using JWT via Knox
Home-page: https://www.cloudera.com/
Author: Cloudera, Inc.
License: Cloudera Standard License
Keywords: raz boto3 jwt knox
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: End Users/Desktop
Classifier: License :: Other/Proprietary License
Classifier: Natural Language :: English
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE.txt
Requires-Dist: raz_client>=1.1.1
Dynamic: author
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: keywords
Dynamic: license
Dynamic: license-file
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# RAZ Client JWT Auth

A Python package that lets your application access **S3 buckets protected by Cloudera's Ranger Authorization Service (RAZ)** using a **JWT token** — no Kerberos required.

It works as a [boto3](https://boto3.amazonaws.com/v1/documentation/api/latest/index.html) plugin: you configure it once, and every S3 call automatically goes through your Knox gateway → RAZ for authorization.

---

## How It Works

```
Your app  →  boto3 S3 call
              ↓
         RazJwtS3Signer (this package)
              ↓  JWT Bearer token
         Knox Gateway → Ranger RAZ
              ↓  signed headers
         AWS S3
```

1. Every boto3 S3 request is intercepted before it is sent.
2. This package contacts your Knox-protected RAZ server using your JWT token.
3. RAZ checks the Ranger policy and returns signed S3 headers.
4. The request is forwarded to S3 with those headers.

---

## Prerequisites

| Requirement | Details |
|---|---|
| Python | 3.10 or higher |
| JWT access token | Obtain from your CDP environment or identity provider |
| RAZ URL | Knox-protected RAZ endpoint, e.g. `https://<knox-host>:8443/<env>/cdp-entraid/rangerraz/` |
| Knox CA certificate *(optional)* | Path to the Knox CA `.pem` file — only needed if Knox uses a private/internal CA |

---

## Installation

```bash
pip install raz_client_jwt_auth boto3
```

> `raz_client` is installed automatically as a dependency.

---

## Quick Start

```python
import boto3
from raz_client import Configuration, RAZ_URL_KEY, SSL_CERT_LOCATION, USE_SSL_VERIFICATION
from raz_client_jwt_auth import configure_ranger_raz_jwt

# 1. Create a boto3 S3 client
client = boto3.client("s3")

# 2. Build the configuration
conf = Configuration()
conf[RAZ_URL_KEY] = "https://<knox-host>:8443/<env>/cdp-entraid/rangerraz/"

# 3. SSL setup — pick ONE of the three options below:

# Option A (most common): Knox uses a private/internal CA — provide the CA cert
conf[SSL_CERT_LOCATION] = "/path/to/cdp-knox-ca.pem"

# Option B: Knox uses a publicly signed cert — no extra line needed,
#           USE_SSL_VERIFICATION defaults to True and uses the system trust store

# Option C: Disable SSL verification entirely — for testing only, not recommended in production
# conf[USE_SSL_VERIFICATION] = False

# 4. Register the JWT signer with the boto3 client
configure_ranger_raz_jwt(client, token="eyJ...", conf=conf)

# 5. Use the client normally
result = client.list_objects_v2(Bucket="my-bucket", Prefix="my/prefix/")
print(result)
```

---

## SSL Configuration

SSL verification is **enabled by default**. The behaviour depends on which config keys you set:

| `USE_SSL_VERIFICATION` | `SSL_CERT_LOCATION` | Result |
|---|---|---|
| `True` *(default)* | Set to a `.pem` path | Verifies Knox cert against your CA file |
| `True` *(default)* | Not set | Verifies using the system trust store |
| `False` | — | SSL verification disabled *(testing only)* |

---

## Supported S3 Operations

- `get_object` / `head_object`
- `list_objects_v2`
- `put_object` / `delete_object`
- `upload_file` / `upload_fileobj`
- `download_file` / `download_fileobj`

See the [raz_client README](../raz_client/README.md) for the complete list.

---

## Full Example

A runnable example covering all operations is in the examples folder. Run it directly using environment variables:

```bash
export RAZ_URL="https://<knox-host>:8443/<env>/cdp-entraid/rangerraz/"
export JWT_TOKEN="eyJ..."
export BUCKET="my-bucket"
export KEY="path/to/existing/file.csv"
export SSL_CERT="/path/to/cdp-knox-ca.pem"   # optional
export WRITE_KEY="path/to/write/test.txt"      # optional, enables write/delete test

python3 -m raz_client_jwt_auth.examples.jwt_s3_example
```

---

## Configuration Reference

| Constant | Config Key | Required | Description |
|---|---|---|---|
| `RAZ_URL_KEY` | `fs.s3a.ext.raz.rest.host.url` | ✅ Yes | Knox-protected RAZ server URL with port |
| `SSL_CERT_LOCATION` | `raz.client.ssl.cert.location` | No | Absolute path to Knox CA cert (private CAs only) |
| `USE_SSL_VERIFICATION` | `raz.client.use.ssl.verification` | No | `True` by default. Set `False` to disable SSL (not recommended) |
| `RAZ_CLIENT_ENABLE_DEBUG_MODE` | `raz.client.enable.debug.mode` | No | Set `True` to print full debug logs |
| JWT token | — | ✅ Yes | Passed as `token=` argument to `configure_ranger_raz_jwt()` |

---

## Troubleshooting

| Error | Cause | Fix |
|---|---|---|
| `ValueError: JWT token must be provided` | `token` argument is empty or whitespace | Pass a valid JWT string |
| `ValueError: RAZ URL must be set` | `RAZ_URL_KEY` not set in config | Set `conf[RAZ_URL_KEY]` before calling `configure_ranger_raz_jwt` |
| `SSL: CERTIFICATE_VERIFY_FAILED` | Knox uses a private CA but no cert provided | Set `conf[SSL_CERT_LOCATION]` to your Knox CA `.pem` path |
| `401 Unauthorized` | JWT token expired or invalid | Refresh your JWT token |
| `403 Forbidden` | Ranger policy denied the operation | Check your Ranger S3 policy for this user/bucket |

---

## Development

From `raz_client_jwt_auth/`:

```bash
make setup
make test
```

Integration tests against a live cluster: `raz_client_jwt_auth/test/integration_test_jwt_s3.py`

---

## License

Copyright (c) 2026 Cloudera, Inc. All Rights Reserved.
This software is governed by the Cloudera Standard License — see [LICENSE.txt](./LICENSE.txt) or the [Cloudera License page](https://www.cloudera.com/legal/terms-and-conditions/cloudera-standard-license/cloudera-standard-license-v9-2019-12-12.html).
