Codefresh behind the firewall
How to run Codefresh pipelines in your own secure infrastructure
As explained in the installation page Codefresh offers 3 installation options: pure cloud, on-premise and Hybrid. In this page we are going to describe the Hybrid option and all the advantages it offers.
Running Codefresh in secure environments
Codefresh has an on-premise installation where the whole platform is installed in the customer premises. While this solution is very effective as far as security is concerned, it places a lot of overhead on the customer as all updates and improvements done in the platform must also be transferred to the customer premises.
The hybrid approach places only a Codefresh runner within customer premises while the UI (and management platform) stays in the Codefresh SAAS.
Here is the overall architecture:
The advantages for this scenario are multi-fold. Regarding platform maintenance:
- The heavy lifting for platform maintenance is still happening by Codefresh instead of the customer.
- Updates to the UI, build engine, integrations etc are happening automatically without any customer involvement.
- Actual builds are happening in the customer premises under fully controlled conditions.
- The Codefresh runner is fully automated. It handles volume claims and build scheduling on its own within the Kubernetes cluster it is placed.
Regarding security of services:
- Pipelines can run in behind-the-firewall clusters with internal services.
- Pipelines can use integrations (such as docker registries) that are private and secure.
- Source code does not ever leave the customer premises.
Regarding firewall security:
- Communication between the Codefresh runner and Codefresh SAAS is uni-directional. The runner is polling the Codefresh platform for jobs.
- Communication between the Codefresh runner and Codefresh SAAS is only outgoing. The Codefresh SAAS never connects to the customer network. No ports need to be open in the customer firewall for the runner to work.
- The Codefresh runner is fully open-source, so its code can by scrutinized by any stakeholder.
Using Secure services in your pipelines
First make sure that you have installed the Codefresh runner on your own infrastructure (i.e. your private Kubernetes cluster).
All pipelines that are executed in the private Kubernetes cluster have access to all other internal services that are network reachable. It is therefore very easy to create pipelines that
- Use databases internal to the company
- Run integration tests against services internal to the company
- Launch compositions that communicate with other secure services
- Upload and download artifacts from a private artifact repository (e.g. Nexus or Artifactory)
- Deploy to any other cluster accessible in the secure network
- Create infrastructure such as machines, load balancers, auto-scaling groups etc
Any of these pipelines will work out the box and no extra configuration is needed. In all cases all data will stay with the private local network and will never exit the firewall.
Notice that long running compositions (preview test environments) are not yet available via the Codefresh build runner.
Checking out code from a private GIT repository
To check-out code from your private GIT repository, you need to connect first to Codefresh via the GIT integrations. However, once you define your GIT provider as on premise you also need to mark it as behind the firewall as well:
Once you do that save your provider and make sure that it has the correct tags. The name you used for the git provider will also be used in the pipeline. You cannot “test the connection” because the Codefresh SAAS doesn’t have access to your on-premise GIT repository.
To check out code just use a clone step like any other clone operation. The only thing to remember is that the GIT URL must be fully qualified. You need to create a pipeline on it its own from the Pipelines section of the left sidebar (instead of one adding a git repository to Codefresh)
Once you trigger the pipeline, the Codefresh builder will communicate with your private GIT instance and checkout code.
Note that currently there is a limitation in regards to the location of the
codefresh.ymlfile. Only the inline mode is supported. Soon we will allow the loading of the pipeline from the git repository itself.
Adding triggers from private GIT repositories
In the previous section we have seen how a pipeline can checkout code from the internal git repository. We also need to setup a trigger so that every time a commit happens (or any other supported event), the Codefresh pipeline will be triggered automatically.
This is a two-step process:
- First we setup a webhook endpoint in Codefresh.
- Then we create the webhook call in the side of the the GIT provider.
For the Codefresh side, follow the usual instructions for creating a basic git trigger.
Once you select your GIT provider, you need to manually enter your username and repository that you wish to trigger the build.
All other details (git events, branch naming, monorepo pattern, etc.) are still the same as normal SAAS GIT providers. Once that is done, Codefresh will show you the webhook endpoint along with a secret for triggering this pipeline. Note them down.
This concludes the setup on the Codefresh side. The final step is create a webhook call on the side of your GIT provider. The instructions are different per GIT provider:
In all cases make sure that the payload is JSON, because this is what Codefresh expects.
- For GitHub the events monitored should be
- For Gitlab the events monitored should be
Tag push eventsand
Merge request events.
After the setup is finished, the Codefresh pipeline will be executed every time a git event happens.
Accessing an internal docker registry
To access an internal registry just follow the instructions for adding registries . Like GIT repositories you need to mark the Docker registry as Behind the firewall.
Once that is done, use the push step as usual with the name you gave to the registry during the integration setup.
Deploying to an internal Kubernetes cluster
To connect a cluster that is behind the firewall follow the connecting cluster guide, paying attention to the following two points:
- Your cluster should be added as a Custom provider
- You need to mark the cluster as internal by using the toggle switch.
The cluster where the runner works on should have network connectivity with the cluster you wish to deploy to.
Notice that the service account used in the cluster configuration is completely independent from the privileges granted to the Codefresh build runner. The privileges needed by the runner are only used to launch Codefresh pipelines within your cluster. The Service account used in the “custom provider” setting should have the needed privileges for deployment.