Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Commit

Permalink
java-openliberty: use ENV variables for security credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
awisniew90 committed Apr 23, 2020
1 parent 516d028 commit 262c8aa
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 14 deletions.
36 changes: 30 additions & 6 deletions incubator/java-openliberty/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ The `mpMetrics` feature enables MicroProfile Metrics support in Open Liberty. No

Metrics endpoint: http://localhost:9080/metrics

#### Metrics Password

Log in as the `admin` user to see both the system and application metrics in a text format. The password for this `admin` user will be generated by the container.
#### Metrics Credentials
For local development, default credentials are provided. Log in as the `admin` user to see both the system and application metrics in a text format. The password for this `admin` user will be generated by the container.

To get the generated password for project **my-project**, you can exec in the container like this, for example:

Expand All @@ -51,6 +51,7 @@ To get the generated password for project **my-project**, you can exec in the co

So in the above example the password value would be: `2r1aquTO3VVUVON7kCDdzno`


### OpenAPI

The `mpOpenAPI` feature provides a set of Java interfaces and programming models that allow Java developers to natively produce OpenAPI v3 documents from their JAX-RS applications. This provides a standard interface for documenting and exposing RESTful APIs.
Expand Down Expand Up @@ -115,6 +116,29 @@ The command `appsody test` launches the Open Liberty server, runs integration te
* At the time of the release of this java-openliberty stack, this problem seems to be getting the active attention of the Docker Desktop for Windows developement team, (e.g. see [this issue](https://github.com/docker/for-win/issues/5530)). Naturally, updating your Docker Desktop for Windows installation might help, however, we can not simply point to a recommended version that is known to work for all users.
* **Workaround**: This may be worked around by making the changes from the host, and then doing a `touch` of the corresponding files from within the container.

## Application Deployment

### Providing security credentials in deployment

Default security credentials are provided for local development. These default values are removed from the official deployment image which simply exposes username and password credentials as environment variables.
You can set these variables by adding the following to app-deploy.yaml where `mySecret` is the name of a pre-defined Secret in your namespace:

```bash
env:
- name: STACK_USERNAME
valueFrom:
secretKeyRef:
key: username
name: mySecret
- name: STACK_PASSWORD
valueFrom:
secretKeyRef:
key: password
name: mySecret
```

This will set environment variables in the deployment called `STACK_USERNAME` and `STACK_PASSWORD` which map to the username and password of `mySecret` respectively.

## Other externals and usage notes

The stack itself defines an externals worth noting here, which is not apparent from the default template:
Expand All @@ -123,10 +147,10 @@ The stack itself defines an externals worth noting here, which is not apparent f

This can be used to abstract over the differences between the install location in each of the local development (`appsody run/debug/test`) vs. image build (`appsody build`) scenarios.

### Config dropin: **quick-start-security.xml**
### Config dropin: **default-credentials.xml**

The metrics endpoint is secured with a userid and password enabled through the config dropin included in the default template at path:
**src/main/liberty/config/configDropins/defaults/quick-start-security.xml**.
The metrics endpoint is secured with a default userid and generated password enabled through the config dropin included in the default template at path:
**src/main/liberty/config/configDropins/defaults/default-credentials.xml**.

In order to lock down the production image built via `appsody build` this file is deleted during the Docker build of your application production image. (The same file would be deleted if you happened to create your own file at this location as well).

Expand Down
6 changes: 3 additions & 3 deletions incubator/java-openliberty/image/project/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ COPY --chown=java_user:java_group ./user-app /project/user-app

# Build (and run unit tests)
# also liberty:create copies config from src->target
# also remove quick-start-security.xml since it's convenient for local dev mode but should not be in the production image.
# also remove default-credentials.xml since it's convenient for local dev mode but should not be in the production image.
RUN cd /project/user-app && \
echo "QUICK START SECURITY IS NOT SECURE FOR PRODUCTION ENVIRONMENTS. IT IS BEING REMOVED" \
rm -f src/main/liberty/config/configDropins/defaults/quick-start-security.xml && \
echo "DEFAULT CREDENTIALS ARE NOT SECURE FOR PRODUCTION ENVIRONMENTS. THEY ARE BEING REMOVED" && \
rm -f src/main/liberty/config/configDropins/defaults/default-credentials.xml && \
mvn -Pappsody-build -B liberty:create package

# process any resources or shared libraries - if they are present in the dependencies block for this project (there may be none potentially)
Expand Down
2 changes: 1 addition & 1 deletion incubator/java-openliberty/stack.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Open Liberty
version: 0.2.8
version: 0.2.9
description: Eclipse MicroProfile & Jakarta EE on Open Liberty & OpenJ9 using Maven
license: Apache-2.0
language: java
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<server>
<!-- These are default credentials provided for local development.
This XML file is removed when the application is deployed. -->
<variable name="stack.username" defaultValue="admin"/>
<variable name="stack.password" defaultValue="${keystore_password}"/>
</server>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<server description="Default security configuration">

<quickStartSecurity userName="${stack.username}" userPassword="${stack.password}" />

</server>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<featureManager>
<feature>microProfile-3.2</feature>
</featureManager>

<httpEndpoint host="*" httpPort="${default.http.port}"
httpsPort="${default.https.port}" id="defaultHttpEndpoint"/>

Expand Down

0 comments on commit 262c8aa

Please sign in to comment.