Skip to content

Conversation

@vreff
Copy link
Contributor

@vreff vreff commented Sep 22, 2025

This PR adds a capability API web controller that can be used to make calls to the capabilities on the node directly. It is useful for E2E tests.

The PR also does some refactoring on test code:

  • Removes use of hardcoded paths for local CRE
  • Exports useful Vault DON test helpers to their own file
  • Adds external target registration to framework/DONs
  • Fixes a syntax error in writer_don_load_test.go and workflow_don_load_test.go

All of which makes it easier to test 3rd party capabilities on CRE.

@vreff vreff changed the title Priv 135 add capability controller Add capability API controller, refactor test code Sep 23, 2025
@vreff vreff marked this pull request as ready for review September 23, 2025 19:21
@vreff vreff requested review from a team as code owners September 23, 2025 19:21
@vreff vreff requested a review from Tofel September 26, 2025 14:04
Tofel
Tofel previously approved these changes Sep 26, 2025
"github.com/smartcontractkit/chainlink/v2/core/capabilities/vault/vaulttypes"
)

func FetchVaultPublicKey(t *testing.T, gatewayURL string) (publicKey string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we keep this private unless there's some reason for it to be public? (I don't see anything in this PR but I may have missed it)

Copy link
Contributor Author

@vreff vreff Sep 26, 2025

Choose a reason for hiding this comment

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

Will result in downstream duplication as we use this in our E2E test, DM'ing. If you prefer it stay private, that's fine, just some duplicate code.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah no then it's OK 👍

authv2.GET("/find_lca", auth.RequiresRunRole(lcaC.FindLCA))

capContr := CapabilityController{app}
authv2.POST("/execute_capability", auth.RequiresRunRole(capContr.ExecuteCapability))
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmm... the implementation of RequiresRunRole is suspicious:

// RequiresRunRole extracts the user object from the context, and asserts the user's role is at least
// 'run'
func RequiresRunRole(handler func(*gin.Context)) func(*gin.Context) {
	return func(c *gin.Context) {
		user, ok := GetAuthenticatedUser(c)
		if !ok {
			c.Abort()
			jsonAPIError(c, http.StatusUnauthorized, errors.New("not a valid session"))
			return
		}
		if user.Role == clsessions.UserRoleView {
			c.Abort()
			jsonAPIError(c, http.StatusUnauthorized, errors.New("Unauthorized"))
			return
		}
		handler(c)
	}
}

Looks like any view role user can execute this, probably a long-standing bug that we would fix.

I'm not sure we would want to enable this endpoint in production builds -- can we use build.IsDev() or similar and only register it if that's true?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done: 8e811fd.

@cl-sonarqube-production
Copy link

@Tofel Tofel self-requested a review September 26, 2025 15:51
@cedric-cordenier cedric-cordenier added this pull request to the merge queue Sep 26, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Sep 26, 2025
@Tofel Tofel added this pull request to the merge queue Sep 26, 2025
Merged via the queue into develop with commit f1ac655 Sep 26, 2025
310 of 315 checks passed
@Tofel Tofel deleted the PRIV-135-add-capability-controller branch September 26, 2025 17:11
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.

3 participants