Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: protect the metadata - basic auth #111

Merged
merged 41 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
1541f5c
initial commit
aramovic79 Jan 22, 2025
4bc4300
add authentication types
aramovic79 Jan 22, 2025
51dc01e
tmp change
aramovic79 Jan 23, 2025
c550441
added open and basic authentication to the ORD document endpoint, as …
aramovic79 Jan 27, 2025
863f155
additional changes related to ucl-mtls
aramovic79 Jan 29, 2025
1c06279
add TODO - renewal of trusted subjects
aramovic79 Jan 29, 2025
62fbd9b
add success tests for ucl-mtls auth
aramovic79 Jan 29, 2025
2b969c7
add ucl-mtls unsuccessfull auth test
aramovic79 Jan 29, 2025
43822b6
added ucl-CA url
aramovic79 Jan 30, 2025
edd7152
fix bug in getTrustedSubject function
aramovic79 Jan 30, 2025
1c0c8cf
cover all branches with tests
aramovic79 Jan 30, 2025
9b44310
added authentication section into the README.md
aramovic79 Jan 30, 2025
5d4d06d
update snapshots
aramovic79 Jan 30, 2025
68aebe8
renamed route-urls
aramovic79 Jan 31, 2025
408164a
corrected the path to the ORD document
aramovic79 Jan 31, 2025
62cef40
updated snapshot
aramovic79 Jan 31, 2025
4efbdee
removed all UCL-mTLS -related logic
aramovic79 Jan 31, 2025
b484301
Merge branch 'main' of https://github.com/cap-js/ORD into feat/52-pro…
aramovic79 Feb 4, 2025
9cb4901
Changes of url for ord and resource definition files
aramovic79 Feb 6, 2025
554d36e
increse code coverage to 100
aramovic79 Feb 7, 2025
e496c03
Change WWW-Authenticate header in case of basic authentication
aramovic79 Feb 10, 2025
45fc23f
rename APP_USER into BASIC_AUTH
aramovic79 Feb 10, 2025
18a7ccd
increase code-branch coverage and address review comments
aramovic79 Feb 10, 2025
574b7c0
rename type into typeS
aramovic79 Feb 11, 2025
7066919
address review comments
aramovic79 Feb 11, 2025
ea39259
minor change: fix non-initialized authConfiguration error
aramovic79 Feb 11, 2025
fdc9c18
minor change
aramovic79 Feb 11, 2025
1f2c5c7
Merge branch 'main' into feat/52-protection-of-metadata
aramovic79 Feb 18, 2025
b22d366
rename ORD_AUTH env variable
aramovic79 Feb 18, 2025
6b9b4d2
Update README.md
aramovic79 Feb 18, 2025
75042cd
Apply suggestions from code review
aramovic79 Feb 18, 2025
07e07d6
minor change - removal of ucl-mtls auth type
aramovic79 Feb 18, 2025
d5a089c
added missing tests and further renaming
aramovic79 Feb 20, 2025
af2344a
Address review comments
aramovic79 Feb 21, 2025
d38f9ab
tmp
aramovic79 Feb 24, 2025
014eeb5
revert the change
aramovic79 Feb 24, 2025
9ae0d91
added the encryption of sensitive data
aramovic79 Feb 24, 2025
f673cf4
increase the code coverage - add test for checking if the pass is bcr…
aramovic79 Feb 24, 2025
4659ffb
minor change
aramovic79 Feb 24, 2025
84bf000
Replace the link to the ORD document with the link to the ORD config doc
aramovic79 Feb 24, 2025
2a2e343
fix the url
aramovic79 Feb 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,28 @@ The following rule governs code contributions:
## Development Setup

As this is a CAP plugin, it is best to develop in the following calesi environment:
```

```bash
git clone --recursive https://github.com/cap-js/calesi.git
cd calesi
npm i
```

Then clone this repository inside the calesi projects plugin folder:
```

```bash
cd plugins
git clone https://github.com/cap-js/ORD
cd ORD
npm i
```

For testing an example app is available in the `xmpl` folder:
```

```bash
#If not already globally installed, install cds-dk
npm install -g @sap/cds-dk
cds w xmpl
```
After the CAP app has started, open this link in your browser: http://localhost:4004/open-resource-discovery/v1/documents/1

After the CAP app has started, open this link in your browser: <http://localhost:4004/.well-known/open-resource-discovery>
81 changes: 77 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ You can use this information to construct a static metadata catalog or to perfor

For more information, have a look at the [Open Resource Discovery](https://sap.github.io/open-resource-discovery/) page.

> ⚠ By installing this plugin, the metadata describing your CAP application will be made openly accessible.
>
> If you have a need to protect your metadata, please refrain from installing this plugin until we support metadata protection (planned).
> ⚠ By installing this plugin, the metadata describing your CAP application will be made openly accessible. If you want to secure your CAP application's metadata, configure `basic` authentication by setting the environment variables or updating the `.cdsrc.json` file. The plugin prioritizes environment variables, then checks `.cdsrc.json`. If neither is configured, metadata remains publicly accessible.

## Requirements and Setup

Expand All @@ -22,6 +20,81 @@ For more information, have a look at the [Open Resource Discovery](https://sap.g
npm install @cap-js/ord
```

### Authentication

To enforce authentication in the ORD Plugin, set the following environment variables:

- `ORD_AUTH_TYPE`: Specifies the authentication types.
- `BASIC_AUTH`: Contains credentials for `basic` authentication.

If `ORD_AUTH_TYPE` is not set, the application starts without authentication. This variable accepts `open` and `basic` (UCL-mTLS is also planned).
> Note: `open` cannot be combined with `basic` or any other (future) authentication types.

#### Open

The `open` authentication type bypasses authentication checks.

#### Basic Authentication

The server supports Basic Authentication through an environment variable that contains a JSON string mapping usernames to bcrypt-hashed passwords:

```bash
BASIC_AUTH='{"admin":"***"}'
```

Alternatively, configure authentication in `.cdsrc.json`:

```json
"authentication": {
"types": ["basic"],
"credentials": {
"admin": "***"
}
}
```

To generate bcrypt hashes, use the [htpasswd](https://httpd.apache.org/docs/2.4/programs/htpasswd.html) utility:

```bash
htpasswd -Bnb <user> <password>
```

This will output something like `admin:$2y$05$...` - use only the hash part (starting with `$2y$`) in your `BASIC_AUTH` JSON.

> [!IMPORTANT]
> Make sure to use strong passwords and handle the BASIC_AUTH environment variable securely. Never commit real credentials or .env files to version control.

<details>
<summary>Using htpasswd in your environment</summary>

- **Platform independent**:

> Prerequisite is to have [NodeJS](https://nodejs.org/en) installed on the machine.

```bash
npm install -g htpasswd
```

After installing package globally, command `htpasswd` should be available in the Terminal.

- **macOS**:

Installation of any additional packages is not required. Utility `htpasswd` is available in Terminal by default.

- **Linux**:

Install apache2-utils package:

```bash
# Debian/Ubuntu
sudo apt-get install apache2-utils

# RHEL/CentOS
sudo yum install httpd-tools
```

</details>

### Usage

#### Programmatic API
Expand All @@ -47,7 +120,7 @@ cds compile <path to srv folder> --to ord [-o] [destinationFilePath]
#### ORD Endpoints

1. Run `cds watch` in the application's root.
2. Check the following relative paths for ORD information - `/.well-known/open-resource-discovery` , `/open-resource-discovery/v1/documents/1`.
2. Check the following relative paths for ORD information - `/.well-known/open-resource-discovery` , `/ord/v1/documents/ord-document`.

<img width="1300" alt="Sample Application Demo" style="border-radius:0.5rem;" src="./asset/etc/ordEndpoint.gif">

Expand Down
18 changes: 9 additions & 9 deletions __tests__/__snapshots__/mockedCsn.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ exports[`Tests for ORD document generated out of mocked csn files Tests for ORD
],
"mediaType": "application/json",
"type": "openapi-v3",
"url": "/.well-known/open-resource-discovery/v1/api-metadata/AdminService.oas3.json",
"url": "/ord/v1/customer.capirebookshopordsample:apiResource:AdminService:v1/AdminService.oas3.json",
},
{
"accessStrategies": [
Expand All @@ -46,7 +46,7 @@ exports[`Tests for ORD document generated out of mocked csn files Tests for ORD
],
"mediaType": "application/xml",
"type": "edmx",
"url": "/.well-known/open-resource-discovery/v1/api-metadata/AdminService.edmx",
"url": "/ord/v1/customer.capirebookshopordsample:apiResource:AdminService:v1/AdminService.edmx",
},
],
"shortDescription": "short description for test AdminService",
Expand Down Expand Up @@ -88,7 +88,7 @@ exports[`Tests for ORD document generated out of mocked csn files Tests for ORD
],
"mediaType": "application/json",
"type": "openapi-v3",
"url": "/.well-known/open-resource-discovery/v1/api-metadata/CatalogService.oas3.json",
"url": "/ord/v1/customer.capirebookshopordsample:apiResource:CatalogService:v1/CatalogService.oas3.json",
},
{
"accessStrategies": [
Expand All @@ -98,7 +98,7 @@ exports[`Tests for ORD document generated out of mocked csn files Tests for ORD
],
"mediaType": "application/xml",
"type": "edmx",
"url": "/.well-known/open-resource-discovery/v1/api-metadata/CatalogService.edmx",
"url": "/ord/v1/customer.capirebookshopordsample:apiResource:CatalogService:v1/CatalogService.edmx",
},
],
"shortDescription": "short description for test CatalogService",
Expand Down Expand Up @@ -140,7 +140,7 @@ exports[`Tests for ORD document generated out of mocked csn files Tests for ORD
],
"mediaType": "application/json",
"type": "openapi-v3",
"url": "/.well-known/open-resource-discovery/v1/api-metadata/CinemaService.oas3.json",
"url": "/ord/v1/customer.capirebookshopordsample:apiResource:CinemaService:v1/CinemaService.oas3.json",
},
{
"accessStrategies": [
Expand All @@ -150,7 +150,7 @@ exports[`Tests for ORD document generated out of mocked csn files Tests for ORD
],
"mediaType": "application/xml",
"type": "edmx",
"url": "/.well-known/open-resource-discovery/v1/api-metadata/CinemaService.edmx",
"url": "/ord/v1/customer.capirebookshopordsample:apiResource:CinemaService:v1/CinemaService.edmx",
},
],
"shortDescription": "short description for test CinemaService",
Expand Down Expand Up @@ -199,7 +199,7 @@ exports[`Tests for ORD document generated out of mocked csn files Tests for ORD
],
"mediaType": "application/json",
"type": "asyncapi-v2",
"url": "/.well-known/open-resource-discovery/v1/api-metadata/AdminService.asyncapi2.json",
"url": "/ord/v1/customer.capirebookshopordsample:eventResource:AdminService:v1/AdminService.asyncapi2.json",
},
],
"shortDescription": "short description for test AdminService",
Expand Down Expand Up @@ -228,7 +228,7 @@ exports[`Tests for ORD document generated out of mocked csn files Tests for ORD
],
"mediaType": "application/json",
"type": "asyncapi-v2",
"url": "/.well-known/open-resource-discovery/v1/api-metadata/CatalogService.asyncapi2.json",
"url": "/ord/v1/customer.capirebookshopordsample:eventResource:CatalogService:v1/CatalogService.asyncapi2.json",
},
],
"shortDescription": "short description for test CatalogService",
Expand Down Expand Up @@ -257,7 +257,7 @@ exports[`Tests for ORD document generated out of mocked csn files Tests for ORD
],
"mediaType": "application/json",
"type": "asyncapi-v2",
"url": "/.well-known/open-resource-discovery/v1/api-metadata/CinemaService.asyncapi2.json",
"url": "/ord/v1/customer.capirebookshopordsample:eventResource:CinemaService:v1/CinemaService.asyncapi2.json",
},
],
"shortDescription": "short description for test CinemaService",
Expand Down
Loading