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

Extra vars poc #203

Merged
merged 18 commits into from
May 23, 2024
Merged

Extra vars poc #203

merged 18 commits into from
May 23, 2024

Conversation

ramavenkata-loya
Copy link
Contributor

Desired Outcome

Please describe the desired outcome for this PR. Said another way, what was
the original request that resulted in these code changes? Feel free to copy
this information from the connected issue.

Implemented Changes

Describe how the desired outcome above has been achieved with this PR. In
particular, consider:

  • What's changed? Why were these changes made?
  • How should the reviewer approach this PR, especially if manual tests are required?
  • Are there relevant screenshots you can add to the PR description?

Connected Issue/Story

Resolves #[relevant GitHub issue(s), e.g. 76]

CyberArk internal issue ID: [insert issue ID]

Definition of Done

At least 1 todo must be completed in the sections below for the PR to be
merged.

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

@ramavenkata-loya ramavenkata-loya requested a review from a team as a code owner April 30, 2024 14:21
andytinkham
andytinkham previously approved these changes May 7, 2024
Copy link
Contributor

@andytinkham andytinkham left a comment

Choose a reason for hiding this comment

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

LGTM from a security view

Copy link
Contributor

@john-odonnell john-odonnell left a comment

Choose a reason for hiding this comment

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

Looks good so far - left one important comment about how we handle the authn_token_file var. I think it would be a good idea to add an integration test case where we use extra vars to configure the lookup plugin.

CHANGELOG.md Outdated
Comment on lines 9 to 12
## [1.2.3] - 2024-04-30

### Changed
- Enhancement for the lookup plugin to support the extra-vars
Copy link
Contributor

Choose a reason for hiding this comment

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

This should count as a backwards-compatible addition

Suggested change
## [1.2.3] - 2024-04-30
### Changed
- Enhancement for the lookup plugin to support the extra-vars
## [1.3.0] - 2024-04-30
### Added
- Enhancement for the lookup plugin to support the extra-vars

Copy link
Contributor

Choose a reason for hiding this comment

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

can you elaborate more on that John. should this be minor change or description must be updated?

Copy link
Contributor

Choose a reason for hiding this comment

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

Bumping the version from 1.2.2 to 1.2.3 would imply that the only released additions were bug fixes, but this goes a bit beyond that. We're adding a new method of configuring the plugin, so as long as we maintain backwards compatibility, we should bump the version to 1.3.0 instead.

authn_login = self.get_var_value("conjur_authn_login")
authn_api_key = self.get_var_value("conjur_authn_api_key")
cert_file = self.get_var_value("conjur_cert_file")
authn_token_file = self.get_var_value("conjur_authn_token_file")
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we have some unexpected behavior here that breaks backwards compatibility.

Previously, we had a section in the DOCUMENTATION variable that described the conjur_authn_token_file variable, but it was being accessed exclusively as an environment variable, so the specified default value was not being applied. Now that we're accessing the value this way, the default value is being applied when we would expect it not to.

We either need to add some special handling for this variable to maintain backwards compatibility, or release this as part of a major version bump.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the past, the authn_token_file value was generated by either an environmental variable or the default path (/var/run/conjur/access-token).

The newest modifications allow for the authn_token_file value to be pulled from either the environmental variable, extra variables, or the default path (/var/run/conjur/access-token).

The behavior was the same as earlier, but we have updated only the ini name of authn_token_file.

Copy link
Contributor

Choose a reason for hiding this comment

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

In the past, the authn_token_file value was generated by either an environmental variable or the default path (/var/run/conjur/access-token)

The last part of this isn't true - previously, the lookup plugin checked the CONJUR_AUTHN_TOKEN_FILE environment variable, and if didn't exist, no default value was applied, and instead the plugin retrieved a new authn token.

Check out this PR's Jenkins build, which is failing on the lookup plugin's end-to-end tests.

TASK [Retrieve Conjur variable] ************************************************
fatal: [localhost]: FAILED! => {"msg": "An unhandled exception occurred while templating
  '{{lookup('conjur_variable', 'ansible/test-secret')}}'. Error was a
  <class 'ansible.errors.AnsibleError'>, original message: An unhandled exception
  occurred while running the lookup plugin 'conjur_variable'. Error was a
  <class 'ansible.errors.AnsibleError'>, original message: Conjur authn token
  file `/var/run/conjur/access-token` was not found on the host. Conjur authn token
  file `/var/run/conjur/access-token` was not found on the host"}

The existing DOCUMENTATION variable section describing the authn_token_file parameter is inaccurate, but we aren't using self.get_option, so it isn't being enforced. Backwards compatibility should be maintained if we updated the new authn_token_file section to specify that it doesn't have a default value, and isn't required.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To ensure backward compatibility for conjur_authn_token_file. We have removed the default key parameter in the conjur_authn_token_file documentation section and also added an extra check for conjur_authn_token_file.

if not variable_value and key != "conjur_authn_token_file":
raise AnsibleError("The value of the {0} variable is not set".format(key))

The token can either be selected from environmental/extra-vars variables or generated within the code.

Copy link
Contributor

Choose a reason for hiding this comment

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

plugins/lookup/conjur_variable.py Outdated Show resolved Hide resolved
plugins/lookup/conjur_variable.py Outdated Show resolved Hide resolved
plugins/lookup/conjur_variable.py Outdated Show resolved Hide resolved
plugins/lookup/conjur_variable.py Outdated Show resolved Hide resolved
tests/conjur_variable/test.sh Show resolved Hide resolved
CHANGELOG.md Outdated
Comment on lines 9 to 12
## [1.2.3] - 2024-04-30

### Changed
- Enhancement for the lookup plugin to support the extra-vars
Copy link
Contributor

Choose a reason for hiding this comment

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

Bumping the version from 1.2.2 to 1.2.3 would imply that the only released additions were bug fixes, but this goes a bit beyond that. We're adding a new method of configuring the plugin, so as long as we maintain backwards compatibility, we should bump the version to 1.3.0 instead.

@itsbrugu itsbrugu merged commit c47ecaa into main May 23, 2024
38 of 41 checks passed
@john-odonnell john-odonnell deleted the extra-vars-poc branch May 23, 2024 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants