OSController: De facto Main EntryPoint - Containing the REST EndpointsOCRestClient: Responsible for interacting with OpenShift REST APIs
OSJsonParser: Parses the- JSON Objects shipped with this application in "Resources"
- JSON Strings received for the different kinds of Objects from the OpenShift REST APIs
Utils: Responsible for :- reading the custom configuration (if present) or the default configuration
- Switching on the debug mode
- Generating OpenShift REST API URLs based on the given parameters
- Calculating the SHA1 Hash based on the given parameters
UserController: Responsible for signup (creating new users)Authentication: Logging In and generating a JWT TokenAuthorization: Verifying the JWT TokenSecurityConfig: Configuration for securing the different endpoints of this applicationSecurityConstants: Contains app security related constants like path of the public/private keys, token and namespace file paths
The database used is H2, operated through Hibernate ORM
ApplicationUserRespository: Used for ORM purposes, the corresponding table created in the database is ‘APPLICATION_USER’ApplicationUser: The model used for the above tableUserDetailsServiceImpl: Implementation of Spring's UserDetailsService which is backed by the database to retrieve user details for authentication purposes
-
application.properties: Contains app specific important configuration - database configuration, h2 console (web based access to the database) and logging configuration NOTE: This file is overridden using the OpenShift template for this application -
JSON Files containing
BuildConfigs , BuildRequest, ImageStreamconfiguration templates which are templated with desired values and used during POST requests for creating BuildConfig, Build, or ImageStream There are two different types of BuildConfig templates:
BuildConfigSource: When building from the source using s2iBuildConfigDocker: When building from a dockerfile
All the BuildConfigs and ImageStreams are identified using a unique hash created out of the following parameters:
- Git URL (Mandatory)
- Git Branch (Optional, Default: master)
- Context Directory (Optional)
-
Create a BuildConfig with ImageStream (POST): BuildConfigs and ImageStreams go hand in hand, so we need to create both together, if one fails, the other must not be created!
-
Creating/Starting a Build out of BuildConfig (POST): The builds are identified using their corresponding BuildConfig which in turn corresponds to the unique hash value described above. Parameter required: BuildConfig name
-
Getting ImageStream URL (GET): Gets the URL of the Image if it exists. Parameter required: BuildConfig/ImageStream name
-
Getting Build Status (GET): Used to track the progress of a specific Build. Status could be “Pending”, “Running”, “Completed” or “Failed”. Parameter: BuildConfig name. When there are multiple Builds corresponding to a BuildConfig, fetch the status of the latest build !
-
Getting Build Logs (GET): Used to periodically fetch logs of a specific Build while the build is running. Parameter: Build name
- Get All/Single BuildConfig(s) (GET)
- Get All ImageStream URLs (GET)
- Get a specific Build from the list of Builds of a BuildConfig (GET)
- Delete BuildConfig (DELETE)
- Delete Build (DELETE), Parameter: Build name
- Delete all Builds (DELETE), Parameter: BuildConfig name
- Delete ImageStream (DELETE)
Each request receieved at the OSController is processed and delivered to the REST APIs of the OpenShift cluster. The process looks like this :
Client -> OSController -> OCRestClient -> OpenShift Cluster
The OCRestClient uses Utils and OSJsonParser as helpers to carry out the following things:
Utils: Responsible for generating the correct REST API URL required for different OpenShift object 'kind' , which is used by the OCRestClient to send the request to the OpenShift's REST APIOSJsonParser: It performs two tasks:- Generating the POST Body request by building the Json based request (using the JSON templates from "Resources")
- Parsing the Response received from the OpenShift REST APIs and extracting the relevant information to send back to the user
By default Spring listens to all the login requests (with credentials) at /login
Spring's login mechanism is pretty good, so it would automatically check for valid credentials from the database once we configure the SecurityConfig's authentication manager to use our UserDetailsServiceImpl (Implementation of Spring's UserDetailsService which is backed by the database to retrieve user details for authentication purposes)
Upon Successful authentication, the following things happen:
- The private key in PKCS8 Format (as required by Java, provided by init container of the OpenShift template) is read as an RSA PrivateKey object.
- A JWT Token is created using the username, desired expiration time and signed with our provided private key
- This is returned in the Response Header as well as the Response Body
In the first step, the header is checked, if the token is present.
- The public Key in the DER Format (as required by Java, provided by the init container of the OpenShift template) is read as an RSA PublicKey Object.
- The received token is then parsed using the public key, after checking if a) the token is not malformed, b) token hasn’t expired c) the private key used for signing matches with the public key
If all the conditions are met, the authorization succeeds.
The application uses H2 Database on a file based storage (path configured in application.properties via OpenShift template's ConfigMap) to store the user credentials. Spring is easily able to configure the Database via Hibernate ORM using Spring's JPA feature The credentials for accessing the database are also defined in application.properties
To access the database, we need to connect it using a web browser at the following url http(s)://<base_url>/h2-console, the 'h2-console' path is configurable in application.properties.
When logging in, make sure that the correct filepath of the database is displayed (again, the filepath is defined in application.properties) The database file is mounted via a PVC (Persistent Volume Claim) in OpenShift template.