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

[Schemas] Limit schema service usage to connectors #1563

Closed
Tracked by #1560
hariso opened this issue May 14, 2024 · 2 comments · Fixed by #1701
Closed
Tracked by #1560

[Schemas] Limit schema service usage to connectors #1563

hariso opened this issue May 14, 2024 · 2 comments · Fixed by #1701
Assignees

Comments

@hariso
Copy link
Contributor

hariso commented May 14, 2024

Part of #1560.

The schema service is currently intended to be used by connectors only. To limit the usage of the service to connectors only we should generate a magic cookie that a connector will use to identify itself (can be saved in an environment variable).

We should also run the schema service on a "random" port.

Pull requests:

@hariso hariso mentioned this issue May 14, 2024
17 tasks
@hariso hariso changed the title Limit schema service usage to connectors [Schemas] Limit schema service usage to connectors May 14, 2024
@lovromazgon lovromazgon moved this from Triage to Todo in Conduit Main May 20, 2024
@raulb raulb self-assigned this Jun 18, 2024
@raulb raulb moved this from Todo to In Progress in Conduit Main Jun 18, 2024
@raulb
Copy link
Member

raulb commented Jul 5, 2024

@hariso @lovromazgon apologies I couldn't bring this one home before I took some time off.

What I was planning on doing was adding to pkg/plugin/schema_cookie.go on conduit the following:

package plugin

import (
	"fmt"
	"math/rand"
	"os"
	"strings"
	"time"

	"github.com/conduitio/conduit/pkg/plugin/connector"
)

const charset = "abcdefghijklmnopqrstuvwxyz" +
	"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"

func randomString(length int) string {
	rand.New(rand.NewSource(time.Now().UnixNano()))
	sb := strings.Builder{}
	sb.Grow(length)
	for i := 0; i < length; i++ {
		sb.WriteByte(charset[rand.Intn(len(charset))])
	}
	return sb.String()
}

// GetSchemaCookieValue receives the name of the plugin and the version, and registers into the provided context a cookie that will be used later on to validate if this plugin is registered.
// This cookie will be stored in an environment variable
func GetSchemaCookieValue(pluginName, pluginVersion string) (connector.SchemaCookie, error) {
	name := strings.ToUpper(fmt.Sprintf("%s_%s", pluginName, pluginVersion))
	value := randomString(32)

	if err := registerCookie; err != nil {
		return connector.SchemaCookie{}, err
	}

	return connector.SchemaCookie{
		Name:  name,
		Value: value,
	}, nil

}

func registerCookie(cookie connector.SchemaCookie) error {
	return os.Setenv(cookie.Name, cookie.Value)
}

@raulb raulb moved this from In Progress to Todo in Conduit Main Jul 5, 2024
@raulb raulb removed their assignment Jul 5, 2024
@hariso
Copy link
Contributor Author

hariso commented Jul 8, 2024

@raulb No problems at all, you already did a lot and didn't leave us much work at all!

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

Successfully merging a pull request may close this issue.

2 participants