Skip to content

Bitbucket Server Provider does not support custom SSH port or HTTP context path #742

@fbuchmeier-abi

Description

@fbuchmeier-abi

Hi!

I've just tried out the new bitbucketserver with the following configuration:

apiVersion: notification.toolkit.fluxcd.io/v1beta3
kind: Provider
metadata:
  name: bitbucket
  namespace: flux-system
spec:
  type: bitbucketserver
  address: ssh://git@mybitbucketserver:2222/ap/fluxcd-sandbox.git
  secretRef:
    name: bitbucket-token
---
apiVersion: notification.toolkit.fluxcd.io/v1beta3
kind: Alert
metadata:
  name: bitbucket
  namespace: flux-system
spec:
  providerRef:
    name: bitbucket
  eventSources:
    - kind: Kustomization
      name: flux-system
---
apiVersion: notification.toolkit.fluxcd.io/v1beta3
kind: Alert
metadata:
  name: helm-release-succeeded
spec:
  eventMetadata:
    name: app-name
    namespace: app-namespace
    version: 0.328.0
  eventSeverity: info
  eventSources:
  - kind: HelmRelease
    name: grafana
    namespace: acp-observability
  exclusionList:
  - .*uninstall.*
  - .*test.*
  inclusionList:
  - .*succeeded.*
  providerRef:
    name: bitbucket
  summary: Summary - HelmRelease successfully reconciled

Unfortunately the provider is not functioning with either the following SSH or HTTPS urls:

When using SSH, the provider (ghcr.io/fluxcd/notification-controller:v1.2.3) exits with a panic:

github.com/fluxcd/notification-controller/internal/notifier/bitbucketserver.go:195 +0x315
github.com/fluxcd/notification-controller/internal/notifier/bitbucketserver.go:155 +0x4e8

As far as I can see, this panic has been fixed in #722
However, due to the current implementation of parsing Git URLs, the resulting HTTPS URL would look like this: https://mybitbucketserver:2222/... which of course does not make any sense.

When using HTTPS, the controller can not validate the repository URL with the following error:

{
  "level": "error",
  "ts": "2024-02-15T09:57:23.947Z",
  "logger": "event-server",
  "msg": "failed to dispatch notification",
  "eventInvolvedObject": {
    "kind": "Kustomization",
    "namespace": "flux-system",
    "name": "flux-system",
    "uid": "3d28463c-9809-4ca7-ab4e-ef7f05c6f395",
    "apiVersion": "kustomize.toolkit.fluxcd.io/v1",
    "resourceVersion": "369853"
  },
  "Alert": {
    "name": "bitbucket",
    "namespace": "flux-system"
  },
  "error": "failed to initialize notifier for provider bitbucket: failed to initialize notifier: invalid repository id \"stash/scm/ap/fluxcd-sandbox\""
}

I've looked up the respective locations in the code and it seems like there currently is no handling for custom (SSH) ports (e.g. 2222) or context paths (e.g /stash) implemented.

For SSH, the host is parsed incorrectly, for HTTPS the project and reposlug end up being wrong because of the additional path component:

Input 0: ssh://git@mybitbucket:2222/ap/fluxcd-sandbox.git
Length:  2
ProjectKey: ap
Reposlug: fluxcd-sandbox
Host: https://mybitbucket:2222

Input 1: https://mybitbucket/stash/scm/ap/fluxcd-sandbox.git
Length:  4
ID: stash/scm/ap/fluxcd-sandbox
ProjectKey: stash
Reposlug: scm
Host: https://mybitbucket

To solve this would it make sense to:

  • only allow HTTPS addresses in the address field of the provider, as any URL inferred from a given SSH URL can always be incorrect (e.g. when running your HTTPS server on another port than 443)
  • restrict the spec.address field to the actual application URL (not the repo clone URL, trim any additional slashes at the end)
  • add new fields for the project key (not name) and repository slug

?

This would introduce a breaking change to the current behaviour but would be much clearer to understand and use in my opinion.

Without introducing breaking changes I could also imagine having an optional spec.contextPath field (or similar) to tell the bitbucket address parser to trim this before trying to determine the project and repository. In addition to this, a note in the docs would be required to inform the user that SSH URLs (with custom ports or installations with custom HTTP context path) are not supported and the user should fall back to using the HTTP Clone URL (+ optional contextPath).

What do you think?

Thank you very much and have a great day,
Florian.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/alertingAlerting related issues and PRsenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions