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

[Feature/redis provider] add redis auth provider #99

Open
wants to merge 22 commits into
base: master
Choose a base branch
from

Conversation

SlZeroth
Copy link
Contributor

  • created provider.go file and i insert that file to all of logic about redisAuthProvider.
  • now createKeyProvider func is include in ServiceSet
  • fix config.yaml file to chose auth type

@SlZeroth
Copy link
Contributor Author

I have a question about implementing the redis Provider. In the existing test code, put StaticProvider in "service.InitializeServer". However, in my code, createKeyProvider is initialized using wire DI. I'm curious what opinions you have on this and how you would like it to be changed.

@@ -9,14 +9,14 @@ import (
"github.com/livekit/livekit-server/pkg/routing"
)

func InitializeServer(conf *config.Config, currentNode routing.LocalNode) (*LivekitServer, error) {
func InitializeServer(conf *config.Config, currentNode routing.LocalNode, isTest bool) (*LivekitServer, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is changed InitializeServer func

Copy link
Member

Choose a reason for hiding this comment

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

we just removed the StaticProvider code to simplify things. sorry, this ended up being a significant change. could you merge and see if issues remain?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no problem. I think remove StaticProvider version is better than before.
Deleting the StaticProvider and the CreateKeyProvider are included in the wire, so it's easier to work with.

@SlZeroth
Copy link
Contributor Author

do you know about it ?

Error: The process '/opt/hostedtoolcache/mage-action/1.11.0/x64/mage' failed with exit code 1

in my local mage testall commend is work

@@ -190,7 +190,9 @@ func startServer(c *cli.Context) error {
return err
}


Copy link
Member

Choose a reason for hiding this comment

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

probably not worth changing this file just for spacing? :)

@@ -30,6 +30,7 @@ type Config struct {
KeyFile string `yaml:"key_file"`
Keys map[string]string `yaml:"keys"`
LogLevel string `yaml:"log_level"`
AuthType string `yaml:"auth_type"`
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
AuthType string `yaml:"auth_type"`
KeyProvider string `yaml:"key_provider"`

can you also run go fmt / goimports on files in this commit?

}

func (p *RedisBasedKeyProvider) GetSecret(key string) string {
fmt.Print("GetSecret CALLED", "\n")
Copy link
Member

Choose a reason for hiding this comment

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

let's get rid of prints from the code

@@ -60,6 +60,9 @@ keys:
key1: secret1
key2: secret2

auth_type: redis
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
auth_type: redis
# # auth details could be stored in Redis. when enabled, ....
# key_provider: redis

once we decide the redis structure, let's include notes on how they keys should be stored in redis.


func (p *RedisBasedKeyProvider) GetSecret(key string) string {
fmt.Print("GetSecret CALLED", "\n")
secret, _ := p.client.Get(context.Background(), key).Result()
Copy link
Member

Choose a reason for hiding this comment

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

I could suggest storing api key/secret in a hash key. it's very hard to remove an API key without a hash of some sort. it's possible to use a hash with a name of "livekit-keys", and storing api key as key of the hash, and secret in the value.. i.e. HGET livekit-keys APIxxxxx

}

func (p *RedisBasedKeyProvider) NumKeys() int {
return 1
Copy link
Member

Choose a reason for hiding this comment

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

this should return HLEN(...)

@@ -157,3 +163,34 @@ func permissionFromGrant(claim *auth.VideoGrant) *livekit.ParticipantPermission
}
return p
}

func createKeyProvider(client *redis.Client, conf *config.Config) (auth.KeyProvider, error) {
Copy link
Member

Choose a reason for hiding this comment

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

this seems to be completely duplicated from CreateKeyProvider.

@@ -9,6 +9,7 @@ import (
"github.com/livekit/livekit-server/pkg/routing"
)


Copy link
Member

Choose a reason for hiding this comment

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

similarly, this file didn't need to be changed.

@davidzhao
Copy link
Member

could you remove .DS_Store as well? 🙏

} else {
return nil, errors.New("conf.auth_type value is not current")
}
}

Choose a reason for hiding this comment

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

New line here.

@@ -25,4 +26,4 @@ func InitializeRouter(conf *config.Config, currentNode routing.LocalNode) (routi
)

return nil, nil
}
}

Choose a reason for hiding this comment

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

Should we have a newline here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for your review :)

@SlZeroth
Copy link
Contributor Author

SlZeroth commented Sep 7, 2021

  • fix AuthType to KeyProvider in config.go file
  • use hget when get api key

Copy link
Member

@davidzhao davidzhao left a comment

Choose a reason for hiding this comment

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

Sorry I had dropped the ball on this. This is a good time for us to re-evaluate how we are storing keys in the config. Just proposed something that is more extensible, and I'm happy to collaborate on this to finish it up too.

@@ -30,6 +30,7 @@ type Config struct {
KeyFile string `yaml:"key_file"`
Keys map[string]string `yaml:"keys"`
LogLevel string `yaml:"log_level"`
KeyProvider string `yaml:"key_provider"`
Copy link
Member

Choose a reason for hiding this comment

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

Thinking that it'd be more extensible to make this into a struct. It'll make it more flexible in the future to customize the behavior. for example:

type KeyProviderConfig struct {
	// env (default), config, file, redis
	Kind string `yaml:"kind"`
	// used with config and env. we could migrate the top level keys to here.
	Keys map[string]string
	// used with file provider
	Path string
	// key to use as the hash to load keys
	RedisKey string `yaml:"redis_key"`
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Path string what is that property mean?
because config is only one file and config file include KeyProvider information so I think Path property doesn't need .

Copy link
Member

Choose a reason for hiding this comment

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

Path can be used for the file provider.. where it could read from a separate keyfile. This is supported today, while probably not a commonly used path.

@SlZeroth
Copy link
Contributor Author

Sorry i will start this task from now on
I plan to communicate slowly while reflecting the requirements.

@SlZeroth
Copy link
Contributor Author

SlZeroth commented Nov 29, 2021

@davidzhao

The requirements for the KeyProvider structure were applied.
and I added test code for testing RedisKeyProvider.
and I applied cli option "key-provider-kind" for user choice provider

I'd appreciate it if you let me know what needs to be fixed or added.

@initpwn
Copy link

initpwn commented Dec 31, 2021

Any update on this PR?

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

None yet

5 participants