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

Adding filename to master key generation Issue #419 #435

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

palak-chaturvedi
Copy link

Updated with respect to the new configuration.c changes.

  • Can add -c conf-file to the master-key generation
    pgagroal-admin -c conf-file -g master-key
  • The pgagroal_get_master_key() is also updated to access the master_key_file_location from the conf file.

@jesperpedersen @fluca1978

@jesperpedersen
Copy link
Collaborator

Please, use the same pull request, and force push changes instead of opening new ones...

@palak-chaturvedi
Copy link
Author

Okk I will continue in this
There were some merge conflicts in it. I was not able to pull all the new commits from the master branch. So I thought I would make it much cleaner in this one.

Copy link
Collaborator

@fluca1978 fluca1978 left a comment

Choose a reason for hiding this comment

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

I need some time to test this, but at glance it seems there is extra work to setup the configuration in the pgagroal-admin.

src/admin.c Outdated
{
if (!remote_connection)
{
errx(1, "Host (-h) and port (-p) must be specified to connect to the remote host");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is pgagroal-admin supposed to be able to connect to the remote host? It doesn't even contain the arguments the message is claiming to use. I suspect there is extra copy and paste here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

pgagroal-admin is local only, pgagroal-cli can do remote

Copy link
Author

Choose a reason for hiding this comment

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

I was not sure how to handle the error when conf file is not specified. I copied the cli one.
I will remove the remote connection thing.

src/admin.c Outdated

while (1)
{
static struct option long_options[] =
{
{"config", required_argument, 0, 'c'},
Copy link
Collaborator

Choose a reason for hiding this comment

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

isn't m less confusing than c?

Copy link
Collaborator

Choose a reason for hiding this comment

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

c is for main configuration file, otherwise it is another letter

Copy link
Author

Choose a reason for hiding this comment

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

I have used main configuration file to add the master_key_file_location.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think for admin.c we just need the explicit -m option e.g. no -c

src/admin.c Outdated
memcpy(&config->common.log_path[0], logfile, MIN(MISC_LENGTH - 1, strlen(logfile)));
}

if (pgagroal_start_logging())
Copy link
Collaborator

Choose a reason for hiding this comment

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

is pgagroal-admin using the logging subsystem?

{
warnx("No home directory for user \'%s\'", username);
mkdir(&buf[0], S_IRWXU);
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we catch a failure here?

Copy link
Author

Choose a reason for hiding this comment

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

I haven't made any modifications to this part. This is already written in the master branch. I just indented it for those cases where filename is not provided.
I can look into it if there is some error?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I haven't made any modifications to this part. This is already written in the master branch. I just indented it for those cases where filename is not provided. I can look into it if there is some error?

Ok, if you will, please check for possible errors, or will postpone.

@fluca1978
Copy link
Collaborator

@palak-chaturvedi please be patient, let's go back one step: add the -m flag to both pagroal- and pgagroal-admin, so that if specified, the executables can find out the correct location of the master key file and other related stuff. Then we will decide if and how to handle it within the main configuration file.

@palak-chaturvedi
Copy link
Author

If we add the -m flag then we will have to change lots of functions including reloading the configuration files and all the functions in configuration.c .
Is this better option than conf file changing?

@jesperpedersen
Copy link
Collaborator

jesperpedersen commented Apr 6, 2024

It is ok for the pgagroal.conf file, but pgagroal-admin shouldn't depend on that file

@palak-chaturvedi
Copy link
Author

Ok so
If the conf file is not given then all the functions other than those that require master-key should not throw error.

I am working on the -m flag it would change all the configuration.c functions because master key is required in those codes.

@fluca1978
Copy link
Collaborator

I'm wondering if this is rally worth, since it seems to be fairly complex (as of design).

However, mu opinion is that pgagroal.conf should have a setting for the master key file location, and pgagroal-admin should have a -m flag that reflects the same setting. In this way, the configuration of main should be straightforward, while the pgagroal-admin can use the same location specified on the command line.
However, this could cause some confusion, since pgagroal-admin does not ask for a master key location, and will write on the default path, so the user can end up with pgagroal-admin writing in a location and pgagroal looking into another without any error or warning. Is it worth?

@jesperpedersen
Copy link
Collaborator

The master_key_path is in pgagroal.conf, so it will be used for pgagroal. pgagroal-cli also uses pgagroal.conf.

The only binary that you have to change are pgagroal-admin with the -m switch, and pgagroal-vault for the pgagroal-vault.conf configuration

@palak-chaturvedi
Copy link
Author

heyy @fluca1978 I made the changes can you please check once again?

@fluca1978
Copy link
Collaborator

Looks fine. A few comments:

  1. if I try to use a command that do not require a master key file with a wrong master key file, everything works fine. Maybe we should check for the -m usage early in pgagroal-admin:
% pgagroal-admin user ls --master-key-file /this/does/not/exists
luca
  1. if pgagroal does not find the master key file, it warns with the wrong error message:
% pgagroal
pgagroal: Invalid master key file (file </etc/pgagroal/pgagroal_users.conf>)
  1. I would remove master_key_file_location from the configuration and add the -m flag to the pgagroal tool itself.

Remove remote connection part from the admin.c

Added -m flag

Added multiple error types for master key
@fluca1978
Copy link
Collaborator

@palak-chaturvedi in commit 411a0fa you fixed the first problem, good!
Still issue two is there.

% pgagroal                                   
pgagroal: Invalid master key file (file </etc/pgagroal/pgagroal_users.conf>)

and this is related to issue three: I would remove the master key file from the configuration and add the -m option to main.c. Otherwise, if you believe it is better to keep such file in the configuration file, can you please argument your idea?

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

Successfully merging this pull request may close these issues.

None yet

3 participants