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

Illegal mix of collations error after upgrade to 0.7.3 #59

Closed
0xL33t opened this issue Jun 9, 2021 · 5 comments · Fixed by #62
Closed

Illegal mix of collations error after upgrade to 0.7.3 #59

0xL33t opened this issue Jun 9, 2021 · 5 comments · Fixed by #62

Comments

@0xL33t
Copy link

0xL33t commented Jun 9, 2021

Behaviour

Steps to reproduce this issue

  1. Do an upgrade as stated in https://github.com/anonaddy/docker#upgrade to version 0.7.3.
  2. Try to receive a mail with an alias.

Expected behaviour

Mail should be forwarded to recipient address.

Actual behaviour

Mail gets rejected. If I downgrade to anonaddy/anonaddy:0.7.2 everything works again.
See LOGS

Configuration

  • Docker version (type docker --version) : Docker version 20.10.7, build f0df350
  • Docker compose version if applicable (type docker-compose --version) : docker-compose version 1.29.2, build 5becea4c
  • Platform (Debian 9, Ubuntu 18.04, ...) : Ubuntu 20.04.2 LTS
  • System info (type uname -a) : Linux 5.4.0-73-generic AnonAddy 0.8.4 #82-Ubuntu SMP Wed Apr 14 17:39:42 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
  • docker-compose.yml:
---
    version: "2.1"
    services:
      #----------------------------------------------------------------------------------------------------------------
      [...]
      #----------------------------------------------------------------------------------------------------------------
    
      db:
        image: mariadb:10.5
        container_name: anonaddy_db
        command:
          - "mysqld"
          - "--character-set-server=utf8mb4"
          - "--collation-server=utf8mb4_unicode_ci"
        volumes:
          - "/srv/dcserver/appdata/anonaddy_db:/var/lib/mysql"
        environment:
          - "MYSQL_ALLOW_EMPTY_PASSWORD=yes"
          - "MYSQL_DATABASE"
          - "MYSQL_USER"
          - "MYSQL_PASSWORD"
        restart: unless-stopped
    
      redis:
        image: redis:4.0-alpine
        container_name: anonaddy_redis
        restart: unless-stopped
    
      anonaddy:
        image: anonaddy/anonaddy
        container_name: anonaddy
        depends_on:
          - db
          - redis
        ports:
          - 25:25/tcp
        dns:
            - 8.8.8.8
        volumes:
          - "/srv/dcserver/appdata/anonaddy:/data"
          - "/srv/dcserver/appdata/swag/etc/letsencrypt/archive/XXX:/certs"
        env_file:
          - "/srv/dcserver/anonaddy.env"
        environment:
          - "DB_HOST=db"
          - "DB_DATABASE"
          - "DB_USERNAME"
          - "DB_PASSWORD"
          - "REDIS_HOST=redis"
        restart: unless-stopped
    
      #----------------------------------------------------------------------------------------------------------------
      [...]
      #----------------------------------------------------------------------------------------------------------------

Docker info

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Build with BuildKit (Docker Inc., v0.5.1-docker)

Server:
 Containers: 7
  Running: 7
  Paused: 0
  Stopped: 0
 Images: 9
 Server Version: 20.10.7
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc io.containerd.runc.v2 io.containerd.runtime.v1.linux
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: d71fcd7d8303cbf684402823e425e9dd2e99285d
 runc version: b9ee9c6314599f1b4a7f497e1f1f856fe433d3b7
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: default
 Kernel Version: 5.4.0-73-generic
 Operating System: Ubuntu 20.04.2 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 1
 Total Memory: 1.894GiB
 Name: XXX
 ID: 7K2I:VXDD:HBF3:TC2S:ZXWW:7UHE:BSID:RV7R:Q5OH:2J7S:C6AF:K5E6
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

Logs

postfix/smtpd[866]: warning: mysql:/etc/postfix/mysql-recipient-access.cf: query failed: Illegal mix of collations (utf8mb4_unicode_ci,IMPLICIT) and (utf8mb4_general_ci,IMPLICIT) for operation '='
postfix/smtpd[866]: NOQUEUE: reject: RCPT from mail-out23.ewetel.de[212.6.122.23]: 451 4.3.5 <XXX>: Recipient address rejected: Server configuration error; from=<XXX> to=<XXX> proto=ESMTP helo=<mail-out.ewetel.de>
@crazy-max
Copy link
Member

@willbrowningme Is there a db migration to change tables collation to utf8mb4_unicode_ci?

@willbrowningme
Copy link
Member

@crazy-max hmm I do seem to remember this error. I don't think I did any migration, you can try adding charset utf8 after each variable though like this:

DELIMITER $$

USE `anonaddy_database`$$

DROP PROCEDURE IF EXISTS `check_access`$$

CREATE PROCEDURE `check_access`(alias_email VARCHAR(254) charset utf8)
BEGIN
    DECLARE no_alias_exists int(1);
    DECLARE alias_action varchar(7) charset utf8;
    DECLARE username_action varchar(7) charset utf8;
    DECLARE additional_username_action varchar(7) charset utf8;
    DECLARE domain_action varchar(7) charset utf8;
    DECLARE alias_domain varchar(254) charset utf8;

    SET alias_domain = SUBSTRING_INDEX(alias_email, '@', -1);

    # We only want to carry out the checks if it is a full RCPT TO address without any + extension
    IF LOCATE('+',alias_email) = 0 THEN

        SET no_alias_exists = CASE WHEN NOT EXISTS(SELECT NULL FROM aliases WHERE email = alias_email) THEN 1 ELSE 0 END;

        # If there is an alias, check if it is deactivated or deleted
        IF NOT no_alias_exists THEN
            SET alias_action = (SELECT
                IF(deleted_at IS NULL,
                'DISCARD',
                'REJECT')
            FROM
                aliases
            WHERE
                email = alias_email
                AND (active = 0
                OR deleted_at IS NOT NULL));
        END IF;

        # If the alias is deactivated or deleted then increment its blocked count and return the alias_action
        IF alias_action IN('DISCARD','REJECT') THEN
            UPDATE
                aliases
            SET
                emails_blocked = emails_blocked + 1
            WHERE
                email = alias_email;

            SELECT alias_action;
        ELSE
            SELECT
            (
            SELECT
                CASE
                    WHEN no_alias_exists
                    AND catch_all = 0 THEN "REJECT"
                    ELSE NULL
                END
            FROM
                users
            WHERE
                alias_domain IN ( CONCAT(username, '.example.com')) ),
            (
            SELECT
                CASE
                    WHEN no_alias_exists
                    AND catch_all = 0 THEN "REJECT"
                    WHEN active = 0 THEN "DISCARD"
                    ELSE NULL
                END
            FROM
                additional_usernames
            WHERE
                alias_domain IN ( CONCAT(username, '.example.com')) ),
            (
            SELECT
                CASE
                    WHEN no_alias_exists
                    AND catch_all = 0 THEN "REJECT"
                    WHEN active = 0 THEN "DISCARD"
                    ELSE NULL
                END
            FROM
                domains
            WHERE
                domain = alias_domain) INTO username_action, additional_username_action, domain_action;

            # If all actions are NULL then we can return 'DUNNO' which will prevent Postfix from trying substrings of the alias
            IF username_action IS NULL AND additional_username_action IS NULL AND domain_action IS NULL THEN
                SELECT 'DUNNO';
            ELSEIF username_action IN('DISCARD','REJECT') THEN
                SELECT username_action;
            ELSEIF additional_username_action IN('DISCARD','REJECT') THEN
                SELECT additional_username_action;
            ELSE
                SELECT domain_action;
            END IF;
        END IF;
    ELSE
        # This means the alias must have a + extension so we will ignore it
        SELECT NULL;
    END IF;
 END$$

DELIMITER ;

That should fix the issue.

@crazy-max crazy-max mentioned this issue Jun 11, 2021
@Atherel
Copy link

Atherel commented Jun 11, 2021

Had the same issue. Recreating the procedure like @willbrowningme suggested fixed it for me.

@crazy-max
Copy link
Member

@0xL33t @Atherel Can you test with anonaddy/anonaddy:pr-62? Thanks.

@0xL33t
Copy link
Author

0xL33t commented Jun 13, 2021

@crazy-max works fine now. Thanks and great job 👍

@0xL33t 0xL33t closed this as completed Jun 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants