Verify Crisp website ownership before connecting

Crisp is a managed (Model B) connector: Probo holds one plugin token
server-side and each connection carries only a Website ID. Nothing
stops one organization from entering another organization's Website
ID, so prove control of the website before creating the connection.

Probo derives a per-(organization, website) verification code as an
HMAC over the token secret and exposes it through a new
crispVerificationCode query. The customer pastes it into the Probo
plugin's per-website settings; at connect time the resolver reads the
setting back through the managed plugin token and requires a
constant-time match before any row is written. The managed key and
plugin ID come from bootstrap, so the connector stays hidden until the
deployment configures them.

The settings fetch is injected so the create-time gate's branch wiring
is unit-tested (mismatch and not-subscribed reject, internal errors
stay generic, a matching code passes), and the managed-versus-client
key resolution is covered too.

Signed-off-by: Aurélien Sibiril <81782+aureliensibiril@users.noreply.github.com>
This commit is contained in:
Aurélien Sibiril
2026-07-11 16:50:32 +02:00
parent 6435a52f47
commit 37121e7bac
24 changed files with 1294 additions and 18 deletions

View File

@@ -30,6 +30,17 @@ type ConnectorConfig struct {
RawConfig any `json:"config,omitempty"`
Settings any `json:"-"`
RawSettings any `json:"settings,omitempty"`
// APIKey holds the Probo-supplied credential for an api_key-protocol
// connector (ManagedAPIKey providers such as Crisp). It is resolved
// from RawConfig by UnmarshalJSON and registered on the provider
// Registry by probod. Empty for OAuth2 connectors.
APIKey string `json:"-"`
// ResourceID holds an optional Probo-supplied resource identifier for an
// api_key-protocol connector, distinct from the credential (e.g. the
// Crisp plugin ID required by the per-website plugin API). Resolved from
// RawConfig by UnmarshalJSON and registered on the provider Registry by
// probod. Empty for connectors that need no such identifier.
ResourceID string `json:"-"`
}
type ConnectorConfigOAuth2 struct {
@@ -42,6 +53,17 @@ type ConnectorConfigOAuth2 struct {
IntegrationSlug string `json:"integration-slug,omitempty"`
}
// ConnectorConfigAPIKey carries the Probo-held API key for a
// ManagedAPIKey connector (e.g. Crisp's marketplace plugin token). The
// operator supplies it via bootstrap env; probod registers it on the
// provider Registry so the create-connector resolver can inject it.
// ResourceID is an optional companion identifier (e.g. the Crisp plugin
// ID) some managed connectors need beyond the credential.
type ConnectorConfigAPIKey struct {
APIKey string `json:"api-key"`
ResourceID string `json:"resource-id,omitempty"`
}
func (c *Config) GetSlackSigningSecret() string {
if c.Notifications.Slack.SigningSecret != "" {
return c.Notifications.Slack.SigningSecret
@@ -99,6 +121,14 @@ func (c *ConnectorConfig) UnmarshalJSON(data []byte) error {
oauth2Connector.IntegrationSlug = config.IntegrationSlug
c.Config = &oauth2Connector
case connector.ProtocolAPIKey:
var config ConnectorConfigAPIKey
if err := json.NewDecoder(bytes.NewReader(tmp.RawConfig)).Decode(&config); err != nil {
return fmt.Errorf("cannot unmarshal api key connector config: %w", err)
}
c.APIKey = config.APIKey
c.ResourceID = config.ResourceID
default:
return fmt.Errorf("unknown connector protocol: %q", c.Protocol)
}

View File

@@ -0,0 +1,81 @@
// Copyright (c) 2026 Probo Inc <hello@probo.com>.
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
package probodconfig_test
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.probo.inc/probo/pkg/connector"
"go.probo.inc/probo/pkg/probodconfig"
)
// TestConnectorConfig_APIKeyRoundTrip pins the bootstrap-to-probod path
// for a ManagedAPIKey (Model B) connector: bootstrap emits an api_key
// ConnectorConfig, it is marshalled to JSON, and probod's UnmarshalJSON
// must recover the key on ConnectorConfig.APIKey. This is what lets the
// Crisp plugin token reach the provider registry.
func TestConnectorConfig_APIKeyRoundTrip(t *testing.T) {
t.Parallel()
original := probodconfig.ConnectorConfig{
Provider: "CRISP",
Protocol: connector.ProtocolType("api_key"),
RawConfig: probodconfig.ConnectorConfigAPIKey{
APIKey: "identifier:secret",
ResourceID: "plugin-id",
},
}
data, err := json.Marshal(original)
require.NoError(t, err)
var got probodconfig.ConnectorConfig
require.NoError(t, json.Unmarshal(data, &got))
assert.Equal(t, "CRISP", got.Provider)
assert.Equal(t, connector.ProtocolAPIKey, got.Protocol)
assert.Equal(t, "identifier:secret", got.APIKey)
assert.Equal(t, "plugin-id", got.ResourceID)
assert.Nil(t, got.Config, "api_key connectors carry no OAuth2 Connector")
}
// TestConnectorConfig_OAuth2RoundTrip guards the pre-existing OAuth2
// path against regressions from the added api_key branch.
func TestConnectorConfig_OAuth2RoundTrip(t *testing.T) {
t.Parallel()
original := probodconfig.ConnectorConfig{
Provider: "SLACK",
Protocol: connector.ProtocolType("oauth2"),
RawConfig: probodconfig.ConnectorConfigOAuth2{ClientID: "cid", ClientSecret: "secret"},
}
data, err := json.Marshal(original)
require.NoError(t, err)
var got probodconfig.ConnectorConfig
require.NoError(t, json.Unmarshal(data, &got))
assert.Equal(t, "SLACK", got.Provider)
assert.Equal(t, connector.ProtocolOAuth2, got.Protocol)
oauth2c, ok := got.Config.(*connector.OAuth2Connector)
require.True(t, ok)
assert.Equal(t, "cid", oauth2c.ClientID)
assert.Equal(t, "secret", oauth2c.ClientSecret)
}