8000 Changed deSEC controll flow to allow for using existing subdomains with Authkey by wildd0g · Pull Request #2080 · nextcloud/vm · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Changed deSEC controll flow to allow for using existing subdomains with Authkey #2080

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

Closed
wants to merge 13 commits into from

Conversation

wildd0g
Copy link
@wildd0g wildd0g commented Aug 15, 2021

Put individual steps of script into functions, and the functions in a controll flow at the bottom.
Added a path to the control flow for people who already have a subdomain claimed.
Changed some of the text to accomodate the new controll flow.
Added general abbort-exit function, which displays instructions how to run the script at a later time.

#2077

@wildd0g wildd0g changed the title Resolves #2077 Changed deSEC controll flow to allow for using existing subdomains with Authkey Aug 15, 2021
@enoch85
Copy link
Member
enoch85 commented Aug 15, 2021

Haven't tested yet, but please don't use tab, use 4 spaces for indentation.

Thanks!

@wildd0g
Copy link
Author
wildd0g commented Aug 18, 2021

Fixed

@enoch85
Copy link
Member
enoch85 commented Aug 18, 2021

Thanks, I will have a look at this tomorrow or Friday.

@enoch85
Copy link
Member
enoch85 commented Aug 19, 2021

Looking at it today and just tested with my own domain, using the token from DEDYN_TOKEN in the deSEC folder. Got this:

image

Maybe we need to generate a new token after all?

@enoch85
Copy link
Member
enoch85 commented Aug 19, 2021

Aaah, you need to generate a new token from within your admin panel. We should add that, will fix!

@wildd0g
Copy link
Author
wildd0g commented Aug 19, 2021 via email

@wildd0g
Copy link
Author
wildd0g commented Aug 19, 2021 via email

@enoch85
Copy link
Member
enoch85 commented Aug 19, 2021

Well, if we could automate it, it would be great, but I'm not sure that's possible. You can help me come up with an idea to fix it if you have time?

@wildd0g
Copy link
Author
wildd0g commented Aug 19, 2021 via email
< 8000 !-- '"` -->

@enoch85
Copy link
Member
enoch85 commented Aug 19, 2021

What we would like is to generate a new TOKEN by email, so that the user can add that in the same way as a new domain, but for an existing account.

@wildd0g
Copy link
Author
wildd0g commented Aug 19, 2021 via email

@enoch85
Copy link
Member
enoch85 commented Aug 19, 2021

I'm quite happy with the flow right now. If we can automate the flow, sure, but the current way also works as we instruct the user how to do it.

@szaimen If you have time to test it would be appreciated.

@wildd0g
Copy link
Author
wildd0g commented Aug 19, 2021

Is the existing account but not existing subdomain flow correct? It's missing registering the new domain claiming at the moment as far as i can tell...

@enoch85
Copy link
Member
enoch85 commented Aug 19, 2021

Is the existing account but not existing subdomain flow correct? It's missing registering the new domain claiming at the moment as far as i can tell...

I'm not sure I follow. Can you ellaborate, or actually show what you mean?

@wildd0g
Copy link
Author
wildd0g commented Aug 19, 2021

Going throught he controll flow, lats assume the domain is free and they have an account:

while :
do
    prompt_dedyn_subdomain
    # Check for SOA record
    #Let's assume the domain is free:
    if host -t SOA "$DEDYNDOMAIN" >/dev/null 2>&1
    then
        <skipped>
    else

This following check seems to be wrong, if the user entered "no" They don't have an existing account, then the negation turns it into true and it follows the Register with existing account flow?
Any way, let's assume it goes into the Register with existing account flow:

        # Domain is free and available to register
        if ! existing_account
        then
            # Register with existing account
            break
        else
            <skipped>
        fi
    fi
done

prompt_security_token
prompt_dyndns
prompt_tls

So the steps it actually executes is:

prompt_dedyn_subdomain -> ask which subdomain it is for
Check that it is taken (it is not)
existing_account -> check if the user claims to have an existing account (they answer yes and are instructed to make a new auth token)
prompt_security_token -> they enter this token
prompt_dyndns -> dynDNS is activated to use the provided token
prompt_tls -> TLS is activated to use the provided token

Nowhere in that list is the domain, confirmed to be free, actually claimed by/assigned to the user on deSEC's service, right?
I think that is a crucial missing step.
The other situation (domain taken) should be able to skip that, since it is taken by the user in question.

@enoch85
Copy link
Member
enoch85 commented Aug 19, 2021

The argument is changed in the latest version, please check again.

Still, we have a loop going on, working on it now.

@wildd0g
Copy link
Author
wildd0g commented Aug 19, 2021

I'm going to really rework this script, it currently functions off of claiming the domain at account creation on deSEC, and using the included account recovery authtoken for the rest.

That is also the source of the weird requirement that any new domain required an as of yet unused email.

I envision the best way to do it would be:

Ask if user has an account (yes/no):
    If no:
        Prompt for credentials (email/password) to create account with (and ask to activate it/complete Captcha in first login).
        Auto login using entered credentials (generates login authtoken)
    if yes:
        Prompt for credentials to log in with
        Auto login (generates login authtoken)
Prompt subdomain from user.
Check if subdomain free
    if yes:
         register new subdomain (Check for maximum amount of domains registered is exceeded)
    if no:
        Check if it exists in subdomains associated with account
        if yes:
            break
        if no:
            Prompt for different subdomain or abort

Ask user to set up DynDNS (yes/no)
    if yes:
        Generate new token for DynDNS using API
        Current DynDNS setup using this new token
        
Ask user to set up TLS (yes/no)
    if yes:
        Generate new token for TLS using API
        Current TLS  setup using this new token

Invalidate/delete current login token

@enoch85
Copy link
Member
enoch85 commented Aug 19, 2021

@wildd0g Found any solution to the email issue, or do you think that the current one works?

@wildd0g
Copy link
Author
wildd0g commented Aug 19, 2021

As i mentioned, currently reworking the script/flow.

Getting the login functionality working is not as easy, extracting the token from the responce stored to file is providing a bit of a challenge.

@enoch85
Copy link
Member
enoch85 commented Aug 19, 2021

As i mentioned, currently reworking the script/flow.

But it works as it is right now, at least in my testing. Anything missing you think?

@enoch85
Copy link
Member
enoch85 commented Aug 19, 2021

You can also assume that 99% of the users doesn't have an account with deSEC, so that shouldn't be a priority/first question.

@wildd0g
Copy link
Author
wildd0g commented Aug 19, 2021

Mostly that horrible behavior of not being able to add new domains to an existing account currently, due to the fact domain claiming is done by using the added 'domain' option in the account creation API.

I'm 90% done with a reworked version that separates out the domain claiming from account creation. Since the control flow is also separated from the rest, changing the order later to favor first checking domain availability and then account existence should be trivial.

@enoch85
Copy link
Member
enoch85 commented Aug 19, 2021

OK, gotcha. 👍 If you're interested in investing some time, maybe you could have a look at this as well?

#1994

@wildd0g
Copy link
Author
wildd0g commented Aug 19, 2021

So while playing around, I believe i got the
run_script NETWORK ddclient-configuration
part to fail, since this git repo is not in /var/scripts in my development environment.
But there are some things that are important to clean up, like the auth keys stored as variables, and I believe the cleanup portion did not trigger on that crash.
Van/do we have to do something about that?

@wildd0g
Copy link
Author
wildd0g commented Aug 19, 2021

By the way, do you have an occupied domain that I can test the "domain taken that you do not own" behavior against?

@enoch85
Copy link
Member
enoch85 commented Aug 19, 2021

Van/do we have to do something about that?

Change the repo to to yours for the testing part, all the scripts exists in your fork as well. In lib.sh there are several mentions, and then you need to change the source URL as well.

do you have an occupied domain that I can test the "domain taken that you do not own" behavior against?

I just test random domains and delete them afterwards, either manually, or with the delete account script included in the deSEC menu.

@wildd0g
Copy link
Author
wildd0g commented Aug 19, 2021

Well, I believe it finally works as intended.

Using while: do and continue as a substitute for a goto feels so weird/dirty, but if can't do it as you should, then you should do it as you can.
Same with repeated

if prompt_try_different_domain
    then
        continue
    else
        aborted_exit_message
    fi

blocks.

I put them in a function at first, but apparently doing a break or continue in a function does not propagate to the outer loop.

Have a look, the behavior should be as I described above.

Also something to note, the login generates a token that is valid for 1 day and gets removed after 7 (if i understand deSEC right) which can manage other tokens.
The tokens generated for the DynDNS and TLS are valid indefinitely, get their own custom names, but don't have the rights to manage other tokens.

szaimen and others added 9 commits August 20, 2021 00:22
Signed-off-by: szaimen <szaimen@e.mail.de>
Signed-off-by: wildd0g <mpeppelman2008@hotmail.com>
Signed-off-by: wildd0g <mpeppelman2008@hotmail.com>
1. Since the script now works with existing accounts, make a new function to ask for that, and use it in the final composition.
2. Domain available? Ask for existing account to register it with
3. Domain taken? Ask for existing account to register it with

Signed-off-by: wildd0g <mpeppelman2008@hotmail.com>
Signed-off-by: wildd0g <mpeppelman2008@hotmail.com>
Signed-off-by: wildd0g <mpeppelman2008@hotmail.com>
Signed-off-by: wildd0g <mpeppelman2008@hotmail.com>
Signed-off-by: wildd0g <mpeppelman2008@hotmail.com>
Signed-off-by: wildd0g <mpeppelman2008@hotmail.com>
Signed-off-by: wildd0g <mpeppelman2008@hotmail.com>
@wildd0g
Copy link
Author
wildd0g commented Aug 20, 2021

So that was an entire mess.

I signed off all your previous commits as well, since DCO was complaining about them.
See if the new version is acceptable, otherwise we can revert to
d4b811f
if needed.

@enoch85
Copy link
Member
enoch85 commented Aug 20, 2021

This feel uncomfortable to merge.

Please revert to the proposed commit. That works at least. I'll merge that, and then we start over with this.

@enoch85
Copy link
Member
enoch85 commented Aug 20, 2021

We can continue to work in this, I'll merge the changes from the original idea in another PR: #2088

You can start clean backing up your changes, then create a new PR to get a clean start.

@enoch85
Copy link
Member
enoch85 commented Aug 20, 2021

Did a test now with no account, and no domain. Noticed this:

desec.sh: line 190: -Po: command not found.

Also, TLS doesn't work as the hook seems to be gone. You changed the name of the most important token to RETURNTOKEN, please revert that change, else we have to change in several scripts and I see no reason to change the name of that variable.

@enoch85
Copy link
Member
enoch85 commented Aug 20, 2021

But I like the idea, instead of registering the domain, we register an account, and connects the domain to that account. 👍

Some code styling, and minor fixes, but generally great!

@enoch85
Copy link
Member
enoch85 commented Aug 20, 2021

We should also implement this:

# Check if deSEC is already installed
print_text_in_color "$ICyan" "Checking if deSEC is already installed..."
if ! is_desec_installed
then
    # Ask for installing
    install_popup "$SCRIPT_NAME"
else
    # Ask for removal or reinstallation
    reinstall_remove_menu "$SCRIPT_NAME"
    # Removal
    run_script ADDONS remove_desec
    removal_popup "$SCRIPT_NAME"
fi

It requires that we remove some of the assumptions in the removal script, or simply copy the code from the removal script to the main install script.

@wildd0g
Copy link
Author
wildd0g commented Aug 20, 2021

So i did that revert to d4b811f you asked for, but that also undid a merge you performed?

@wildd0g
Copy link
Author
wildd0g commented Aug 20, 2021

We should also implement this:

# Check if deSEC is already installed
print_text_in_color "$ICyan" "Checking if deSEC is already installed..."
if ! is_desec_installed
then
    # Ask for installing
    install_popup "$SCRIPT_NAME"
else
    # Ask for removal or reinstallation
    reinstall_remove_menu "$SCRIPT_NAME"
    # Removal
    run_script ADDONS remove_desec
    removal_popup "$SCRIPT_NAME"
fi

It requires that we remove some of the assumptions in the removal script, or simply copy the code from the removal script to the main install script.

I'm... confused, what functionality do you want to add with that?

Also, I'm taking a look at the subdomain and removal scripts, they call 'is_desec_installed' but i can't seem to find where that is defined?
Never mind, found it in the lib script.
Would it be preferable to put some more general functionality, like adding/removing domains, in lib as opposed to in each specific script?

@enoch85
Copy link
Member
enoch85 commented Aug 20, 2021

So i did that revert to d4b811f you asked for, but that also undid a merge you performed?

Remove your fork, delete the repo. Git pull fresh, and start over. But first, (let me take a selife) copy your current code in desec.sh so that you can add that back on the fresh clone.

Would it be preferable to put some more general functionality, like adding/removing domains, in lib as opposed to in each specific script?

Yes, I would like it to work as with "Activate TLS" where we make a function out of the TLS stuff for deSEC so that we can use that repo wide if needed, in the same way as with the regular TLS. I made a script for adding subdomains, but I'm not sure that works with Collabora|Onlyoffice|Talk and other apps that needs TLS on a separate subdoman. I wrote a list here: #1994

The removal function is great, but we need to implement it here as well as the removal script is assumed to be run standalone.

@enoch85
Copy link
Member
enoch85 commented Aug 20, 2021

Also, yes, generally we put all functions into lib.sh, but in this case I see no need for it as they're only used in desec.sh. If there are functions that are used in more places, they should go into lib.sh.

Thinking about it, one is actually aborted_error_message, that would go into lib, since we use the same text elsewhere as well.

@wildd0g
Copy link
Author
wildd0g commented Aug 20, 2021

Just to confirm, I'm to remove my fork entirely and start from scratch? In stead of closing this pull request, update my fork to the newest master, and continue onward with my branch in another pull request?

@enoch85
Copy link
Member
enoch85 commented Aug 20, 2021

Just to confirm, I'm to remove my fork entirely and start from scratch? In stead of closing this pull request, update my fork to the newest master, and continue onward with my branch in another pull request?

Do as you wish, but we need a clean slate here. As long as it's the latest master, I'm fine with it. 👍

@wildd0g
Copy link
Author
wildd0g commented Aug 20, 2021

👍Closing this PR

@wildd0g wildd0g closed this Aug 20, 2021
@enoch85
Copy link
Member
enoch85 commented Aug 18, 2022

@wildd0g Hey, just wondering if you ha any plans on improving deSEC further? You talked about a refactor IIRC.

@wildd0g
Copy link
Author
wildd0g commented Aug 19, 2022 via email

@enoch85
Copy link
Member
enoch85 commented Aug 20, 2022

OK, no stress. Just switched house myself this month, I know the work load!

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.

3 participants
0