A Operator based on the Operator SDK to run the Mobile Security Service on a OpenShift/Kubernetes cluster.
By the following commands you will create a local directory and clone this project.
$ git clone git@github.com:aerogear/mobile-security-service.git $GOPATH/src/github.com/aerogear/mobile-security-service-operator
Install Minishift then enable Operators on it by running the following commands.
# create a new profile to test the operator
$ minishift profile set mss-operator
# enable the admin-user add-on
$ minishift addon enable admin-user
# add insecure registry to download the images from docker
$ minishift config set insecure-registry 172.30.0.0/16
# start the instance
$ minishift start
Update the cluster host IP into the MobileSecurityService CR
ℹ️
|
The clusterHost will be used to generated the route/ingress source as in the ConfigMap created with the SDK JSON config.
|
Use the following command to create the Operator, Service and its Database as apply the roles on the cluster.
$ make create-all
❗
|
To create all you need be logged as admin. Use oc login -u system:admin .
|
-
Create a MobileSecurityServiceBind CR as this example.
-
The app name and appId need to be specified into the MobileSecurityServiceBind CR as follows.
# The appName spec defines the name of the app used to bind the service appName: "app" # The appId spec defines the appId of the app used to bind the service appId: "appid"
❗Do not forget to update the clusterHost into the MobileSecurityServiceBind CR -
Run the following command to bind the app to the Mobile Security Service
$ make bind
-
Create a MobileSecurityServiceUnbind CR as this example.
-
Add into into the MobileSecurityServiceUnbind CR the app id as follows.
# The appId spec defines the appId of the app used to bind the service appId: "appid"
❗Do not forget to update the clusterHost into the MobileSecurityServiceUnbind CR -
Run the following command to unbind the app from the service
$ make unbind
The environment variables are used to configure the Mobile Security Service Application and Database. For a further understatement over its configuration see Setup and Configurations section in Mobile Security Service README.
NOTE:
-
All values used in the default configuration came from the config-map which is managed and created by the Operator. This config map will be created in the Operator namespace and its name is defined by the attribute
configMapName
in the MobileSecurityService CR. -
If the name of this ConfigMap be not specified then the name of the Mobile Security Service instance will be used instead of.
-
The MobileSecurityServiceDB and MobileSecurityService should have specified the same name for this ConfigMap in order to allow the App and Database share its usage.
Role for no-privilege users are able to create the Mobile Security Service App, Database and/or Bind and Unbind their apps
By executing the following commands you will create roles in the cluster which will allow the <user> create the Mobile Security Service Application and Database in their namespaces. In this would not be required be the system:admin. However, the Mobile Security Service Operator is cluster scoped and will still only accessible for the `system admin users.
$ oc create rolebinding developer-mobile-security-service-operator --role=mobile-security-service-operator --user=<user>
$ oc create rolebinding developer-mobile-security-service --role=mobile-security-service --user=<user>
The database image and its parameters as their default values are configurable and specified by the MobileSecurityServiceDB CR.
This operator is cluster-scoped
. To know more over it see the topic Operator Scope in the Operator Framework documentation. Also, check its roles in Deploy directory.
ℹ️
|
The operator, application and database will be installed in the namespace mobile-security-service-operator which will be created by this project.
|
CustomResourceDefinition |
Description |
Packages, manages, installs and configures the Mobile Security Service on the cluster. |
|
Packages, manages, installs and configures the Mobile Security Service Database on the cluster. |
|
Creates and update the app in the Service REST API and create the SDK Config Map. |
|
Delete the app from the Service REST API. |
-
Resource
Description
Define the ConfigMap resources required for the Mobile Security Service Application and its Database. It will create the mobile-security-service-app` which map the values used in the Environment Variables of both.
Define the Deployment resource of Mobile Security Service Application. (E.g container and resources definitions)
Define the route/ingress resource required to allow access to the Mobile Security Service Application.
Define the Service resource of Mobile Security Service Application.
-
Mobile Security Service Database
Resource
Description
Define the Deployment resource of Mobile Security Service Database. (E.g container and resources definitions)
Define the PersistentVolumeClaim resource used by its Database.
Define the Service resource of Mobile Security Service Database.
-
Resource
Description
Define the ConfigMap resources managed by the Bind. It creates the ConfigMap with the config JSON for the SDK and the app by the REST API. Note that each application has our own Bind CR applied.
-
Status
Description
appStatus
For this status is expected the value
OK
which means that all required Kubernetes/OCP objects are created.configMapName
Name of the configMap created with the Environment Variables.
deploymentName
Name of the deployment object created for the App.
deploymentStatus
Deployment Status from ks8 API. ( v1beta1.DeploymentStatus )
serviceName
Name of the service object created for the App.
serviceStatus
Deployment Status from ks8 API. ( v1.ServiceStatus )
ingressName
Name of the ingress/route object created for the App.
ingressStatus
Ingress Status from ks8 API. ( v1beta1.IngressStatus )
-
Status
Description
databaseStatus
For this status is expected the value
OK
which means that all required Kubernetes/OCP objects are created.deploymentName
Name of the deployment object created for the Database.
deploymentStatus
Deployment Status from ks8 API. ( v1beta1.DeploymentStatus )
serviceName
Name of the service object created for the Database.
serviceStatus
Deployment Status from ks8 API. ( v1.ServiceStatus )
PersistentVolumeClaimName
Name of the PersistentVolumeClaimName object created for the Database.
-
Status
Description
bindStatus
For this status is expected the value
OK
which means that the app was created in the Rest Service API as its SDKConfigMap.SDKConfigMapName
Name of the config map object created for the app with its SDK Config.
-
Status
Description
unbindStatus
For this status is expected the value
OK
which means that the app was deleted in the Rest Service API as its SDKConfigMap.
The following command will install the operator in the cluster and run the changes performed locally without the need to publish a `dev tag. In this way, you can verify your code in the development environment.
$ make run-local
❗
|
The local changes are applied when the command operator-sdk up local --namespace=mobile-security-service-operator is executed then it is not a hot deploy and to get the latest changes you need re-run the command.
|
The tags are published into the Docker Hub.
To publish an new version of this operator based on the master branch following the steps.
-
Update the operator tag version
Replace the tag of the image in the operator.yaml file.
# Replace this with the built image name image: aerogear/mobile-security-service-operator:0.1.0
ℹ️In this example the tag 0.1.0
will be replaced for the new one. -
Replace the tag in the Makefile file.
TAG=0.1.0
ℹ️In this example the tag 0.1.0
will be replaced for the new one.❗Follow the Semantic Versioning to define the new tags -
Build and publish the new version tag in Docker Hub
Run the following commands
$ make build $ make publish
ℹ️
|
You need be logged in the docker and have access to publish images on it. Use $ docker login .
|
The dev tags will allow you test locally the changes performed in the project without affect the tag published into the Docker Hub based on the master branch. The following commands will build the project and publish it with the tag which will be <version>-dev.
$ make build-dev
$ make publish-dev
ℹ️
|
You need be logged in the docker and have access to publish images on it. Use $ docker login .
|
Update the image tag in the file operator.yaml with the development tag as follows.
# Replace this with the built image name
image: aerogear/mobile-security-service-operator:0.1.0-dev
ℹ️
|
The image/tag used from Mobile Security Service is defined in mobile-security-service_v1alpha1_mobilesecurityservice_cr.yaml file. |
Command |
Description |
|
Create mobile-security-service-operator namespace, operator, service and roles |
|
Delete mobile-security-service-operator namespace, operator, service and roles |
|
Create mobile-security-service namespace, operator and roles |
|
Delete mobile-security-service namespace, operator and roles |
|
Create Mobile Security Service App and its database in the project |
|
Create Mobile Security Service App without its database |
|
Delete Mobile Security Service App and its database |
|
Delete Mobile Security Service App only |
|
Create Mobile Security Service Database without its application |
|
Delete Mobile Security Service Database only |
|
Create the Bind CR and delete the Unbind CR examples. (Create/Update app in the Service and add SKD ConfigMap) |
|
Delete the Bind CR and create Unbind CR examples. (Delete app from the Service and SDKConfigMap) |
|
Build operator with its tag |
|
Publish operator in Docker Hub with its tag |
|
Build operator for development proposes |
|
Publish operator in Docker Hub for development proposes |
|
Run the operator locally for development purposes |
|
Examines source code and reports suspicious constructs using vet |
|
Formats code using gofmt |
ℹ️
|
The Makefile is implemented with tasks which you should use to work with. |
This operator was developed using the k8s APIs and should work well in Kubernetes and OpenShift clusters. However, it has been tested on OpenShift clusters only so far.
All contributions are hugely appreciated. Please see our Contributing Guide for guidelines on how to open issues and pull requests. Please check out our Code of Conduct too.
There are a number of ways you can get in in touch with us, please see the AeroGear community.