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

Extra arguments are not parsed correctly #135

Open
waldner opened this issue Jul 25, 2023 · 7 comments
Open

Extra arguments are not parsed correctly #135

waldner opened this issue Jul 25, 2023 · 7 comments

Comments

@waldner
Copy link

waldner commented Jul 25, 2023

When using extra arguments to openconnect (ie those after --), depending on the syntax used an error might be produced, or the results might be unexpected.

❯ openconnect-sso --version
openconnect-sso 0.8.1

For example:

openconnect-sso --log-level=DEBUG --server https://example.com --authgroup foo --user [email protected] -- --script /path/to/my-connection-script

(note the missing = in the --script argument, which is legal syntax) the following openconnect invocation is produced:

[debug    ] Starting OpenConnect           [openconnect_sso.app] command_line=['sudo', 'openconnect', '--useragent', 'AnyConnect Linux_64 4.7.00136', '--version-string', '4.7.00136', '--cookie-on-stdin', '--servercert', 'XXXXXXXXXXXXXXXXXXXXXXXXXXX', '/path/to/my-connection-script', 'https://example.com/']

which openconnect rejects with Too many arguments on command line.

On the other hand, if using the following syntax (also legal):

openconnect-sso --log-level=DEBUG --server https://example.com --authgroup foo --user [email protected] -- --script=/path/to/my-connection-script

(ie with --script=...)

The resulting openconnect invocation is

[debug    ] Starting OpenConnect           [openconnect_sso.app] command_line=['sudo', 'openconnect', '--useragent', 'AnyConnect Linux_64 4.7.00136', '--version-string', '4.7.00136', '--cookie-on-stdin', '--servercert', 'XXXXXXXXXXXXXXXXXXXXXXXXXXX', 'https://example.com/']

which is valid openconnect syntax, but now the extra option is not passed at all, and indeed the custom script is not executed.

@waldner waldner changed the title Extra arguments without equal sign are not parsed correctly Extra arguments are not parsed correctly Jul 25, 2023
@waldner
Copy link
Author

waldner commented Jul 25, 2023

The problem seems to be in the way that argparse.REMAINDER is handled in python 3.11, I'm looking for more information.

@waldner
Copy link
Author

waldner commented Jul 25, 2023

No, in fact the problem is that the fix (https://github.com/vlaci/openconnect-sso/blame/master/openconnect_sso/cli.py#L125) is not in Pypi yet. So, released version 0.8.1 is broken because of this line:

setattr(namespace, self.dest, values[1:])

@vlaci
Copy link
Owner

vlaci commented Jul 30, 2023

If you could check if the latest git master is working, I'll release it

@waldner
Copy link
Author

waldner commented Jul 31, 2023

I'll check it out as soon as I have a moment, thanks.

@waldner
Copy link
Author

waldner commented Jul 31, 2023

Yes master is working (note I only tested this specific thing).

@TechupBusiness
Copy link

@vlaci released?

@zabealbe
Copy link

No, in fact the problem is that the fix (https://github.com/vlaci/openconnect-sso/blame/master/openconnect_sso/cli.py#L125) is not in Pypi yet. So, released version 0.8.1 is broken because of this line:

setattr(namespace, self.dest, values[1:])

I confirm that by manually chaning setattr(namespace, self.dest, values[1:]) to setattr(namespace, self.dest, values) fixes the problem. A temporary solution is to insert a dummy argument such as -V:

openconnect-sso --user [email protected] --server example.io -- -V --script='vpn-slice example.io'

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

No branches or pull requests

4 participants