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

Adds creation of sentinel files for checking provider status #450

Merged
merged 1 commit into from
Mar 22, 2022

Conversation

diverdane
Copy link
Contributor

@diverdane diverdane commented Mar 17, 2022

Desired Outcome

  • SP creates an empty sentinel status file after initially providing secrets (either via secret files or Kubernetes Secrets). The SP creates this file at /conjur/status/CONJUR_SECRETS_PROVIDED, but this can be mounted by an application container via a shared volume mount at any arbitrary location in the container's file system.
  • SP creates an empty sentinel status file whenever secret files or Kubernetes Secrets have been updated. The SP creates this file at /conjur/status/CONJUR_SECRETS_UPDATED, but this can be mounted by an application container via a shared volume mount at any arbitrary location in the container's file system.
  • The SP includes a convenient script at /usr/local/bin/conjur_secrets_provided that waits for the .../CONJUR_SECRETS_PROVIDED to be created. This can be used in a postStart lifecycle hook definition for the SP container, to defer startup of app container until SP has completed its first round of providing secrets.
  • At startup, the SP copies a script that monitors the .../CONJUR_SECRETS_UPDATED file to /conjur/status/conjur_secrets_unchanged. This script returns a non-zero exit status whenever secret files or Kubernetes Secrets have changed. This can be used in a livenessProbe or readinessProbe definition for an application container to force Kubernetes/kubelet to restart this container when secrets have been updated. The Deployment manifest would need to include a volumeMount to mount this directory/file in the application container, along with the livenessProbe / readinessProbe definition.

With the above changes, a postStart lifecycle hook for the Secrets Provider container would look like this:

        lifecycle:
          postStart:
            exec:
              command:
              - /usr/local/bin/conjur-secrets-provided

And a livenessProbe for an application container that would serve as a "file watcher" can potentially look something like this (assuming the livenessProbe is not already being used by the container as a health probe):

        livenessProbe:
          exec:
            command:
            - /mounted/status/conjur-secrets-unchanged
          failureThreshold: 1
          initialDelaySeconds: 5
          periodSeconds: 5
          successThreshold: 1
          timeoutSeconds: 1

Where the application container (and SP container) would need to include volumeMounts similar to this:

        volumeMounts:
        - mountPath: /mounted/status
          name: conjur-status

and the Pod would need a Volume defined:

      volumes:
      - name: conjur-status
        emptyDir:
          medium: Memory

Implemented Changes

  • SP creates an empty /conjur/status/CONJUR_SECRETS_PROVIDED file after initial round of providing secrets.
  • SP creates an empty /conjur/status/CONJUR_SECRETS_UPDATED file whenever secret files or Kubernetes Secrets have been updated**.
  • SP copies a conjur_secrets_unchanged script to /conjur/status in it file system. This directory can be volume mounted by the application container at any arbitrary path in the application container's file system.
  • LOTS of refactoring to minimize the number of arguments passed to the public functions in pkt/secrets. Provider configuration was split up into separate embedded structs for:
    • Common provider config
    • Config specific to Push-to-File
    • Config specific to Kubernetes Secrets destination mode
  • LOTS of refactoring to allow provider functions to return a boolean status indicating target files/Secrets have just been updated, along with an error, rather than just an error. This allows the top-level functions to create the .../CONJUR_SECRETS_UPDATED file when appropriate.
  • LOTS of UT changes to account for refactoring and the new sentinel file functionality.

Connected Issue/Story

CyberArk internal issue link: ONYX-17885

Definition of Done

  • Everything listed in implemented changes are implemented.
  • UT is implemented for new code.

Changelog

  • The CHANGELOG has been updated, or
  • This PR does not include user-facing changes and doesn't require a
    CHANGELOG update

Test coverage

  • This PR includes new unit and integration tests to go with the code
    changes, or
  • The changes in this PR do not require tests

Documentation

  • Docs (e.g. READMEs) were updated in this PR
  • A follow-up issue to update official docs has been filed here: insert issue ID
  • This PR does not require updating any documentation

Behavior

  • This PR changes product behavior and has been reviewed by a PO, or
  • These changes are part of a larger initiative that will be reviewed later, or
  • No behavior was changed with this PR

Security

  • Security architect has reviewed the changes in this PR,
  • These changes are part of a larger initiative with a separate security review, or
  • There are no security aspects to these changes

@diverdane diverdane self-assigned this Mar 17, 2022
@diverdane diverdane requested a review from a team as a code owner March 17, 2022 14:46
@diverdane diverdane force-pushed the post-start-file-create branch from 13ea6db to 1ea9dee Compare March 17, 2022 16:08
@diverdane diverdane force-pushed the post-start-file-create branch 2 times, most recently from 3989326 to 9872fe1 Compare March 18, 2022 22:12
@diverdane diverdane force-pushed the post-start-file-create branch from 9872fe1 to 3ec40b7 Compare March 18, 2022 22:42
@diverdane diverdane changed the title WIP: Adds creation of sentinel files for checking provider status Adds creation of sentinel files for checking provider status Mar 18, 2022
@diverdane diverdane force-pushed the post-start-file-create branch 3 times, most recently from 794e46d to bbe315f Compare March 21, 2022 17:37
Copy link
Contributor

@szh szh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking forward to the walk through. Here are a few initial minor comments.

pkg/secrets/provide_conjur_secrets_test.go Outdated Show resolved Hide resolved
pkg/secrets/provider_status.go Outdated Show resolved Hide resolved
pkg/secrets/provider_status.go Show resolved Hide resolved
@diverdane diverdane force-pushed the post-start-file-create branch from bbe315f to 5ba8969 Compare March 21, 2022 20:01
cmd/secrets-provider/main.go Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@diverdane diverdane force-pushed the post-start-file-create branch from 5ba8969 to 5ed806a Compare March 21, 2022 22:21
@codeclimate
Copy link

codeclimate bot commented Mar 21, 2022

Code Climate has analyzed commit 5ed806a and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 85.9% (50% is the threshold).

This pull request will bring the total coverage in the repository to 89.8% (-0.2% change).

View more on Code Climate.

Copy link
Contributor

@szh szh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants