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

T6486: T6379: Rewrite generate openvpn client-config #3747

Merged
merged 1 commit into from
Jul 30, 2024

Conversation

sever-sever
Copy link
Member

@sever-sever sever-sever commented Jul 2, 2024

Change Summary

This command helps to generate users .ovpn files Rewrite generate openvpn client-config to use Config() It needs to get the default values as ConfigTreeQuery is not supporting default values.

Fixed "ignores configured protocol type" if TCP is used
Fixed lzo, was used even if lzo was not configured
Fixed encryption does not parse the dict

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes)
  • Migration from an old Vyatta component to vyos-1x, please link to related PR inside obsoleted component
  • Other (please describe):

Related Task(s)

Related PR(s)

Component(s) name

openvpn

Proposed changes

How to test

Configure Openvpn in TCP mode,

set interfaces openvpn vtun20 encryption ncp-ciphers 'aes256'
set interfaces openvpn vtun20 hash 'sha512'
set interfaces openvpn vtun20 local-host '203.0.113.1'
set interfaces openvpn vtun20 mode 'server'
set interfaces openvpn vtun20 protocol 'tcp-passive'
set interfaces openvpn vtun20 server subnet '10.0.22.0/24'
set interfaces openvpn vtun20 tls ca-certificate 'openvpn-ca'
set interfaces openvpn vtun20 tls certificate 'openvpn-cert'
set interfaces openvpn vtun20 tls dh-params 'dh'

Before the fix the proto is UDP, but expected TCP
Generated OpenVPN client config file

client
nobind
remote None 1194
remote-cert-tls server
proto udp
dev tun
dev-type tun
persist-key
persist-tun
verb 3
comp-lzo no

After the fix the protocol is correct, encyption with correct maps, lzo not exists:

vyos@vyos# run generate openvpn client-config interface vtun20 ca openvpn-ca certificate openvpn-client

client
nobind
remote 203.0.113.1 1194
remote-cert-tls server
proto tcp-client
dev tun
dev-type tun
persist-key
persist-tun
verb 3

# Encryption options

cipher AES-256-CBC
data-ciphers AES-256-CBC
auth sha512
...

Smoketest result

Checklist:

  • I have read the CONTRIBUTING document
  • I have linked this PR to one or more Phabricator Task(s)
  • I have run the components SMOKETESTS if applicable
  • My commit headlines contain a valid Task id
  • My change requires a change to the documentation
  • I have updated the documentation accordingly

Copy link

github-actions bot commented Jul 2, 2024

👍
No issues in PR Title / Commit Title

Copy link

github-actions bot commented Jul 2, 2024

❌ VyOS CLI smoketests failed!

Copy link
Member

@dmbaturin dmbaturin left a comment

Choose a reason for hiding this comment

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

There are lots of very necessary updates and good ideas here, but I think if we are at it, we can make the script a lot better by integrating it with the pki subtree and converting it to the new-style op mode.

src/op_mode/generate_ovpn_client_file.py Outdated Show resolved Hide resolved
src/op_mode/generate_ovpn_client_file.py Outdated Show resolved Hide resolved
parser.add_argument("-a", "--ca", type=str, help='OpenVPN CA cerificate', required=True)
parser.add_argument("-c", "--cert", type=str, help='OpenVPN client cerificate', required=True)
parser.add_argument("-k", "--key", type=str, help='OpenVPN client cerificate key', action="store")
parser.add_argument(
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason not to convert this scripts to the new-style op mode? I think people may want to retrieve OpenVPN client configs through the API.

Copy link
Member Author

Choose a reason for hiding this comment

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

The script is not ideal.
For example, if the server listen address is not set, which address should be on the client site (x.x.x.x/None/'replace me')?
For now, it generates x.x.x.x, which is not the address. This is not a good solution for the API where all data must be actual, but if it is OK, we can probably overwrite it.

Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should add an argument like strict: book. If it's true, then any incomplete config will result in an exception vyos.opmode.DataUnavailable. If it's false, then the script will output a placeholder, maybe as a commented-out line.

# listen-address is missing from the config
# To make this config usable, add "remote <server address> option, like:
# remote openvpn.example.net

Copy link
Member Author

Choose a reason for hiding this comment

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

It is more bug fix.
Can we merge it as it is and refactor it if required in the separate PR?

help='OpenVPN interface the client is connecting to',
required=True,
)
parser.add_argument(
Copy link
Member

Choose a reason for hiding this comment

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

Those options were more or less direct translations from my really old script that I wrote for use outside of VyOS and then crudely ported to VyOS. At the time explicit options used to make sense, sort of, because certs and keys were stored in files.

But now they are stored in the config, so I think we should remove the explicit CA option and just fetch it from the pki entry.

Copy link
Member Author

Choose a reason for hiding this comment

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

But we get them from PKI as completion helper, we do not use this script directly as separate file
it generates from the command

vyos@vyos# run generate openvpn client-config interface vtun20 ca openvpn-ca certificate openvpn-client

Where openvpn-ca and openvpn-client are certificate names from the PKI path

Copy link
Member

Choose a reason for hiding this comment

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

My point is, the interface already defines which CA to use. There is no reason to ask the user for it separately.

Copy link
Member Author

Choose a reason for hiding this comment

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

To be honest, the tls ca is multi-value

vyos@r4# show interfaces openvpn vtun20 tls ca-certificate 
 ca-certificate ca
+ca-certificate cb
+ca-certificate cc
+ca-certificate cd
[edit]
vyos@r4# 

Copy link
Member

Choose a reason for hiding this comment

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

I wonder if clients should also allow all the same CAs in that case.

Copy link
Member Author

Choose a reason for hiding this comment

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

It will be behavior change and should be processed by a separate PR
If I understand correctly, your goal is replacing CLI op-mode to provide client-cert only as an arg
I.e Before:

generate openvpn client-config interface vtun20 ca openvpn-ca certificate openvpn-client

After:

generate openvpn client-config interface vtun20 certificate openvpn-client

This way all CA's will be included from pki ca based on the vtunX configuration
Do we really need it? If yes, it is better to do it in a separate PR

I never used several CA's for a client. Even in theory is it possible to sign a client cert by several CA's?

Copy link
Member

Choose a reason for hiding this comment

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

Does client mode support multiple CAs? If there are multiple CAs in an organiazation, I suppose the assumption is that the server cert can also be signed with any of them, and thus the client may need to verify the server cert against multiple CAs.

Copy link
Member Author

@sever-sever sever-sever Jul 28, 2024

Choose a reason for hiding this comment

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

Let's fix bugs without new options.
The original bugs https://vyos.dev/T6486 and https://vyos.dev/T6379
And both should solved in this change.

src/op_mode/generate_ovpn_client_file.py Show resolved Hide resolved
This command helps to generate users `.ovpn` files
Rewrite `generate openvpn client-config` to use Config()
It needs to get the default values as `ConfigTreeQuery` is
not supporting default values.

Fixed "ignores configured protocol type" if TCP is used
Fixed lzo, was used even if lzo not configured
Fixed encryption is not parse the dict
Copy link

github-actions bot commented Jul 2, 2024

CI integration 👍 passed!

Details

CI logs

  • 👍 passed CLI Smoketests returned:
  • 👍 passed Config tests returned:
  • 👍 passed RAID1 tests returned:

Copy link
Member

@dmbaturin dmbaturin left a comment

Choose a reason for hiding this comment

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

Ok, let's merge it for the fixes first and figure out the rest later.

@c-po c-po merged commit 80c45be into vyos:current Jul 30, 2024
11 of 12 checks passed
@sever-sever
Copy link
Member Author

@Mergifyio backport circinus sagitta

Copy link
Contributor

mergify bot commented Aug 1, 2024

backport circinus sagitta

✅ Backports have been created

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants